>>> 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'
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.
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 .
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With