itertools.ifilter Vs. filter Vs. list comprehensions

后端 未结 4 1999
孤城傲影
孤城傲影 2020-12-30 22:25

I am trying to become more familiar with the itertools module and have found a function called ifilter.

From what I understand, it filters

4条回答
  •  耶瑟儿~
    2020-12-30 22:44

    ifilter returns a generator, not a list.

    Generators create their items on the fly when needed, instead of allocating the entire list first. That's the only difference between ifilter and filter

提交回复
热议问题