closedset = set()
root = (5,6)
for u,v in root:
if v is not closedset:
closedset.add(root)
print closedset
Error:
for u,v in root:TypeError: unpack non-sequence
What should i do with type of error?
closedset = set()
root = (5,6)
for u,v in root:
if v is not closedset:
closedset.add(root)
print closedset
Error:
for u,v in root:TypeError: unpack non-sequence
What should i do with type of error?
I'm not sure I understand what you're trying to do. Maybe:
roots = [(5, 6), (2, 3)]
for u, v in roots:
if f not in closed:
closed.add(v)
print closed
Note a few changes:
roots is now a list of tuples. for u, v in roots will correctly "unpack" each tuple into u and vif v is not closed your probably meant if f not in closed, if closed is a dictionary of some kindclose.add is a method (of a set?), then it has to be called with parens () and not brackets ()root = ((5, 6),)
or
u, v = root
Depending on what your intentions are.
root = [(5,6)]
...should work. for iterates through a list or set, returning first u, then v. If you want to return both parts of the set, you'll have to add itself to a list.