Friday Finking: initialising values and implied tuples

dn PythonList at DancesWithMice.info
Sun Apr 4 17:53:35 EDT 2021


On 03/04/2021 11.25, Marco Ippolito wrote:
>> (a) basic linear presentation:
>>
>> resource = "Oil"
>> time = 1
>> crude = 2
>> residue = 3
>> my_list = "long"
>>
>> (b) using explicit tuples:
>>
>> ( resource, time, crude, residue, my_list ) = ( "Oil", 1, 2, 3, "long" )
>>
>> (c) linear and indented tuples:
>>
>> (
>>     resource,
>>     time,
>>     crude,
>>     residue,
>>     my_list
>> ) = (
>>     "Oil",
>>     1,
>>     2,
>>     3,
>>     "long"
>> )
> 
> Choose: (a).
> 
> In (b) I have a problem matching identifiers to values horizontally at a
> glance and in (c) I have the same problem vertically: i.e. "is 3 the value for
> residue or crude above/to-the-left?"
> 
> Cognitive burden slows down and fatigues.

+1


> Alternatively, if the data "fits together", use a `namedtuple` with kwarg
> initialisation or structured data types like `dataclasses`.

Whereas the other formats cannot, it would be very easy to turn an (a)
type of list into a dataclass!
-- 
Regards,
=dn


More information about the Python-list mailing list