Обложка канала

Библиотека Python разработчика

20835 @BookPython

Библиотека Python разработчика. Книги по программированию на Python.

Библиотека Python разработчика

4 года назад
Открыть в
If you want to iterate over several iterables at once, the zip function may be a good choice. It returns a generator that yields tuples containing one element from every original iterables: In : eng = ['one', 'two', 'three'] In : ger = ['eins', 'zwei', 'drei'] In : for e, g in zip(eng, ger): ...: print('{e} = {g}'.format(e=e, g=g)) ...: one = eins two = zwei three = drei Notice, that zip accepts iterables as separate arguments, not a list of arguments. To unzip values, you can use the * operator: In : list(zip(*zip(eng, ger))) Out: [('one', 'two', 'three'), ('eins', 'zwei', 'drei')]