Why can't I iterate twice over the same data?

后端 未结 3 1484
余生分开走
余生分开走 2020-11-22 00:59

Honestly I am a little confused here, why can\'t I iterate twice over the same data?

def _view(self,dbName):
    db = self.dictDatabases[dbName]
    data = d         


        
3条回答
  •  庸人自扰
    2020-11-22 01:47

    I want to complete the answer of @ÓscarLópez for them who looks for a solution in 2017 and uses python 2.7 or 3.

    Method tee() takes no keyword arguments now and waits for the second argument an integer, not keyword. This is the right way to use tee():

    import itertools
    it1, it2 = itertools.tee(db[3], 2)
    

提交回复
热议问题