Friday Finking: initialising values and implied tuples

Rob Cliffe rob.cliffe at btinternet.com
Fri Apr 2 21:41:59 EDT 2021



On 02/04/2021 23:10, dn via Python-list wrote:
> (f) the space-saver:
>
> resource = "Oil"; time = 1; crude = 2; residue = 3; my_list = "long"
>
>    
IMO This can be OK when the number of items is VERY small (like 2) and 
not expected to increase (or decrease).  Especially if there are 
multiple similar initialisations:
     x = 1; y = 2
         ...
     x = 2 ; y = 6
This saves vertical space and the similarity of the initialisations may 
be more apparent.  It also means only a single line need be 
cut/pasted/modified.
No doubt others will disagree.

This answer reflects my willingness to use multiple statements on a line 
OCCASIONALLY, WHEN I think it is appropriate (as I have said or implied 
in other posts), whereas many people seem to regard this as completely 
taboo.
Another example:
     x1 = 42; y1 =  3;  z1 = 10
     x2 = 41; y2 = 12; z2 = 9
     x3 =  8;  y3 =  8;  z3 = 10
(please imagine it's in a fixed font with everything neatly vertically 
aligned).
This has see-at-a-glance STRUCTURE: the letters are aligned vertically 
and the "subscripts" horizontally.  Write it as 9 lines and it becomes 
an amorphous mess in which mistakes are harder to spot.
Rob Cliffe


More information about the Python-list mailing list