Найти - Пользователи
Полная версия: Хочу izip как zip
Начало » Python для новичков » Хочу izip как zip
1
Ed
Как бы это покороче сделать аналог zip, но ленивый? В смысле, чтобы он не останавливался, когда кончается короткий итератор, а генерил None, как zip.
s0rg
next_or_none = lambda a: next(a, None)
def izip_large(*iterables):
    iterators = map(iter, iterables)
    while iterators:
        next_item = tuple(map(next_or_none, iterators))
        if not any(next_item):
            return
        yield next_item
for i in izip_large('ABCD', 'xy'):
    print i
?
pyuser
А чем родной zip_longest не устраивает?
Ed
Спасибо! Забыл, вот ведь.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB