Type error in python!
closedset = set()
root = (5,6)
for u,v开发者_JAVA技巧 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?
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.
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:
rootsis now a list of tuples.for u, v in rootswill correctly "unpack" each tuple intouandv- by
if v is not closedyour probably meantif f not in closed, ifclosedis a dictionary of some kind - if
close.addis 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.
for u,v in [root]:
print u,v
will do what you want.
加载中,请稍侯......
精彩评论