Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What happened to ifilter?

In comparing documentation for itertools between Python 2 and 3, I noticed ifilter, imap, izip are missing from Python 3. I suspect this is because many builtin keywords have been converted to generators and replaced former keywords, but it is unclear in this case.

Is it true ifilter, imap, izip are now equivalent to filter, map, zip in Python 3? If not, where can I find rationales for why certain methods were removed from current itertools?

like image 688
pylang Avatar asked Jul 20 '15 05:07

pylang


1 Answers

Python 2.3 introduced the itertools module, which defined variants of the global zip(), map(), and filter() functions that returned iterators instead of lists. In Python 3, those global functions return iterators, so those functions in the itertools module have been eliminated.

enter image description here

  • Instead of itertools.izip(), just use the global zip() function.
  • Instead of itertools.imap(), just use map().
  • itertools.ifilter() becomes filter().
  • The itertools module still exists in Python 3, it just doesn’t have the functions that have migrated to the global namespace. The 2to3 script is smart enough to remove the specific imports that no longer exist, while leaving other imports intact.

Read more here

like image 120
Tharif Avatar answered Oct 26 '22 23:10

Tharif