Proposal: [... for ... while cond(x)]
Diez B. Roggisch
deets at nospam.web.de
Sun Aug 6 20:28:52 EDT 2006
> No, the list comprehension lets you write an expression directly avoiding a
> function call, and it also allows you to add in a condition which can be
> used to filer the sequence. Your proposal adds nothing.
It does. Consider this:
whatever = [x for x in xrange(1000000000) while x < 10]
That would run only in a splitsecond of what the whole listcomp would.
Yet I still fail to see that this is a really useful use-case. takewhile
is easily abstracted away as map and reduce and filter are using lambda
- which I'm a modest supporter of.
But functions that are monotonic such that the takewhile really offers a
advantage over the much more general listcomp + if are IMHO way to
seldom to justify a new syntax.
The overall complexity is still O(n).
Regards,
Diez
More information about the Python-list
mailing list