Re: Comprehensions
"Mark Hahn" <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Paul Prescod wrote: > a = [1,2,3] > print [ x*2 for x in a] > > paul:/tmp pprescod$ ./test.pr > > Parse Error: expecting `']'' > --- File: ./test.pr, line: 4, col: 16 > print [ x*2 for x in a] > ^ > > Uncaught exception: > Parse Error. This is a known unfixable problem with functions-as-commands. It is parsing it as print[index]. I am pulling functions-as-commands so this problem will go away. O>> a = [1,2,3] [1, 2, 3] O>> [ x*2 for x in a] [2, 4, 6] O>> > paul:/tmp pprescod$ python ./test.pr > [2, 4, 6] How did you get this result? > Anyhow, generator comprehensions are more modern than list > comprehensions and you can easily turn a generator comprehension into > a list comprehension explicitly: > > list(x*2 for x in a) > > http://www.python.org/dev/doc/devel/whatsnew/node4.html Ok, I'll put changing list comps into gen comps into the 1.0 list. I had never heard of them before. Are there any other PEPs I should be aware of? This is technically past the new feature submission deadline but I'll stretch the rules for you. :-)