Is it possible to make list comprehension stop when n items are added to the new list?
e.g.,
[x for x in xrange(20) if len(<this>) < 10 ]
To confirm: I wants to limit the length of the resultant list to 10. “” is pseudocode for the current list being made. Im using python 2.7
No. But
itertools.islice()can give you a generator that only yields a given number of items.