After repeating the itertools.combinations
object itertools.combinations
it has been used, and you cannot repeat it a second time.
If you need to reuse it, the correct way is to make it list
or tuple
as you did. All you have to do is give it a name (assign it to a variable) so that it obscures.
combList = list(combObject)
If you want to iterate over it only once, you just don't call list
on it at all:
for i in combObj:
Side note. The standard way to name object instances / normal variables would be comb_obj
, not combObj
. See PEP-8 for details.
To convert the internal tuple
to list
s, use list comprehension and the built-in list()
:
comb_list = [(1, 2, 3), (1, 2, 4), (1, 3, 4), (2, 3, 4)] comb_list = [list(item) for item in comb_list]
source share