枚举压缩列表时,如何避免嵌套元组拆包? [英] How can I avoid nested tuple unpacking when enumerating zipped lists?

查看:71
本文介绍了枚举压缩列表时,如何避免嵌套元组拆包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

枚举像这样的元组列表时,如何避免使用嵌套元组拆包?

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

推荐答案

使用 itertools.count 避免嵌套元组拆包:

Use itertools.count to avoid nested tuple unpacking:

from itertools import count

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

这篇关于枚举压缩列表时,如何避免嵌套元组拆包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆