使用more_itertools

这里要使用到more_itertools这个包,直接用pip安装就可以了

pip install more_itertools

查看迭代器可迭代的次数

import more_itertools
# data是你的迭代器
print(more_itertools.ilen(data))

转换可看长度对象

你也可以将你的迭代器变成一个列表,再查看列表长度。但是这样你的迭代器就变成空的了,建议使用第一种方法。

# data是你的迭代器

print(len(list(data)))

相关文章:

  • 2022-12-23
  • 2022-02-12
  • 2021-10-28
  • 2022-03-05
  • 2021-11-11
  • 2021-10-13
  • 2021-11-12
猜你喜欢
  • 2022-12-23
  • 2022-03-09
  • 2021-06-03
  • 2022-12-23
  • 2021-07-10
  • 2021-12-06
  • 2022-12-23
相关资源
相似解决方案