[英]Unused variable in python enumerate
Im using enumerate to obtain the indexes in a list ("i"), but I don't need the value of every element ("j"). 我使用枚举来获取列表中的索引(“ i”),但是我不需要每个元素(“ j”)的值。 "j" is unused in my code, so this is a warning in the eclipse IDE.
我的代码中未使用“ j”,因此在eclipse IDE中是一个警告。 How I can fix this?
我该如何解决?
Code: 码:
for i,j in enumerate(my_list):
Just because an IDE gives you a warning that doesn't mean you have to change your code. 仅仅因为IDE向您发出警告,并不意味着您必须更改代码。 @WillemVanOnsem gives you the necessary solution to iterating over the indexes in his comment.
@WillemVanOnsem为您遍历其注释中的索引提供了必要的解决方案。
如果只需要索引,则可以使用:
my_index = [i for i in range(len(mylist))]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.