Question on style.

Paul Duffin pduffin at hursley.ibm.com
Fri Sep 15 04:59:38 EDT 2000


Remco Gerlich wrote:
> 
> Paul Duffin wrote in comp.lang.python:
> > Any one like to comment on why this particular order was chosen over
> > the more 'readable' one of for first then expression.
> 
> I *think* this syntax was adopted from functional languages,
> for instance, in Haskell the "list of squares of the numbers 1 to 100" is
>     [ n*n | n <- [1..100] ]
> Which becomes the slightly more verbose
>     [ n*n for n in range(1,101) ]

The single usage is quite readable but when you have multiple uses in
the same expression then it becomes more difficult to read.

How should the example from the original poster be 'read' ?

frames = [[score[frame] for score in scores] \
          for frame in range(3)]

What would a similar mathematical expression be ?

> in Python. It's also like math, where it would be something like
>     { x^2 | x element of N and 1 <= n <= 100 }
                                      ^
Surely this should be x not n.

> 
> I'd pronounce this "the list of squares of the numbers 1 to 100".
> 

Surely the mathematical interpretation is 
    "the set of squares of the numbers 1 to 100"
         ^^^
lists are not a mathematical concept are they ? IANAM.



More information about the Python-list mailing list