Question on style.

Rainer Deyke root at rainerdeyke.com
Mon Sep 11 14:45:34 EDT 2000


"Alex" <cut_me_out at hotmail.com> wrote in message
news:etd7l8isrw6.fsf at oliver.mit.edu...
> # Separate the triple of scores for each sequence into separate parallel
> # lists for each frame.
> frames = [[score[frame] for score in scores] \
>           for frame in range(3)]

I find the order of list comprehensions (with the for part after the
expression) weird, but otherwise don't have any trouble reading the above.
It's compact, which is good, even when it takes more effort to comprehend
each individual line.

Compare the long version:

frames = []
for frame in range(3):
  tmp = []
  for score in scores:
    tmp.append(score[frames])
  frames.append(tmp)

Each line here is easier to read, but the large number of lines and the
temporary variable make the whole thing harder to understand, IMO.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list