Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My IDLE does not recognize itertools.izip() as a function

>>> itertools.izip('ABCD', 'xy')
Traceback (most recent call last):
  File "<pyshell#55>", line 1, in <module>
    itertools.izip('ABCD', 'xy')
AttributeError: 'module' object has no attribute 'izip'
like image 773
Alexander Wright Avatar asked Aug 28 '15 00:08

Alexander Wright


People also ask

What is Izip in Python?

izip() returns an iterator that combines the elements of the passed iterators into tuples. It works similarly to zip() , but returns an iterator instead of a list.

How does itertools combinations work?

The itertools. combinations() function takes two arguments—an iterable inputs and a positive integer n —and produces an iterator over tuples of all combinations of n elements in inputs .


1 Answers

In Python 3, there is no izip function in the itertools module because the builtin zip function (which doesn't require any imports to access) now behaves like itertools.izip did in Python 2. So, to make your code work, just use zip instead of itertools.izip.

You also mentioned an issue with string.maketrans. That's another function that is no longer in a module in Python 3. It's now a method of the str class: str.maketrans. Note however that its behavior is a bit different than string.maketrans in Python 2, as the translate method on strings takes different arguments (a dictionary instead of a 256-character string).

It sounds like you may be following a guide written for Python 2, but using Python 3 to run your code. This can be confusing, as there were signficant changes between the major versions of the language. You should try to find a guide that targets Python 3 instead. I don't recommend using Python 2 for your coding unless you really must follow your current guide.

like image 124
Blckknght Avatar answered Sep 20 '22 16:09

Blckknght