如何避免在以下Python代码中手动递增sequence
计数器:
sequence = 0
for value in random.sample(range(1000), 7):
# do something with value and sequence
sequence += 1
答案 0 :(得分:8)
枚举!您可以参考Python docs。
for sequence, value in enumerate(random.sample(range(1000), 7)):
# do something with value and sequence