How can I avoid nested tuple unpacking when enumerating zipped lists?

荒凉一梦 提交于 2020-01-14 05:46:06

问题


How can I avoid using nested tuple unpacking when enumerating a list of tuples like this?

for i, (x, y) in enumerate(zip("1234", "ABCD")):
    # do stuff

回答1:


Use itertools.count to avoid nested tuple unpacking:

from itertools import count

for i, x, y in zip(count(), "1234", "ABCD"):
    # do stuff


来源:https://stackoverflow.com/questions/11968729/how-can-i-avoid-nested-tuple-unpacking-when-enumerating-zipped-lists

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!