A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2008-May/079770.html below:

[Python-Dev] itertools additions: one(), single_valued()

[Python-Dev] itertools additions: one(), single_valued()Armin Ronacher armin.ronacher at active-4.com
Mon May 26 21:40:49 CEST 2008
Hi,

Andreas Klöckner <lists <at> informa.tiker.net> writes:

>   list_len = single_valued(len(l) for l in lists)
length, = set(map(len, lists))

>   what_i_am_looking_for = one(item for item in items if predicate(item))
Is that really such a common case?  In Python 2.6 you can use next for the same
thing however without the check if there is just one item:

what_i_am_looking_for = next(filter(predicate, items))

What I would like to see is a batch function defined like that:

def batch(iterable, n):
    return izip(*repeat(iter(iterable), n))

It's a common pattern I use it very often.

Regards,
Armin

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4