for index, item in enumerate(Foo()):
    print "index: ", index, " item: ",item

 

用enumerate再封装一次函数返回的迭代,即可支持索引。

C#也可以实现类似的写法

相关文章:

  • 2022-01-22
  • 2021-10-18
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案