exhausted iterators - what to do about them?

前端 未结 4 1032
庸人自扰
庸人自扰 2020-11-29 12:27

(In Python 3.1) (Somewhat related to another question I asked, but this question is about iterators being exhausted.)

# trying to see the ratio of the max an         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 12:58

    The itertools.tee function can help here:

    import itertools
    
    f1, f2 = itertools.tee(filtered, 2)
    ratio = max(f1) / min(f2)
    

提交回复
热议问题