tags:

views:

76

answers:

4
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?

A: 

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 v
  • by if v is not closed your probably meant if f not in closed, if closed is a dictionary of some kind
  • if close.add is a method (of a set?), then it has to be called with parens () and not brackets ()
Eli Bendersky
Actually the problem is: keys = child.keys() - here child is a dictionary root = keys[0] - so this will return - (5,4) Now i need to iterate...for u, v values..I am doing right ?? closed is a set and the commands I used for it are: closedset = set()
Shilpa
A: 
root = ((5, 6),)

or

u, v = root

Depending on what your intentions are.

Matt Joiner
+1  A: 
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.

relet
A: 
for u,v in [root]:
   print u,v

will do what you want.

Wayne Werner