[Python-ideas] Integrate some itertools into the Python syntax
Michel Desmoulin
desmoulinmichel at gmail.com
Wed Mar 23 17:54:19 EDT 2016
Le 23/03/2016 22:26, João Bernardo a écrit :
>
> On Mon, Mar 21, 2016 at 8:06 PM, Michel Desmoulin
> <desmoulinmichel at gmail.com <mailto:desmoulinmichel at gmail.com>> wrote:
>
> Itertools is great, and some functions in it are more used than others:
>
> - islice;
> - chain;
> - dropwhile, takewhile;
>
>
> I like how dropwhile and takewhile could be easily integrated with list
> comprehensions / generator expressions:
>
> [x for x in range(10) while x < 5] # takewhile
> [x for x in range(10) not while x < 5] # dropwhile
> [x for x in range(10) from x >= 5] # forward thinking dropwhile
>
> I believe this is almost plain english without creating new keywords.
>
> Regards
>
Nice. But if you need to combine both it's a long one liner. It could be
combined with enumerate for islicing, but it would then end up huge.
More information about the Python-ideas
mailing list