Re: Comprehensions
Paul Prescod <[email protected]>
| Newsgroups | gmane.comp.lang.prothon.user |
|---|---|
| Message-ID | <[email protected]> |
Mark Hahn wrote:
> Paul Prescod wrote:
>
>
>>Is there a deep reason that Prothon doesn't have
>>comprehensions or is it
>>just not implemented yet? I think that Python programmers
>>would scream
>>if they were left out.
>
>
> Are you talking about list comprehensions? Prothon has list
> comprehensions.
paul:/tmp pprescod$ /usr/local/bin/prothon -v
Prothon 0.1, Build 710, Jul 6 2004
paul:/tmp pprescod$ cat ./test.pr
#!/usr/local/bin/prothon
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.
paul:/tmp pprescod$ python ./test.pr
[2, 4, 6]
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
Paul Prescod