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

1
  • 1
    unpack a sequence, of course... Commented Jul 16, 2010 at 13:19

4 Answers 4

1
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.

Sign up to request clarification or add additional context in comments.

Comments

0

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 ()

1 Comment

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()
0
root = ((5, 6),)

or

u, v = root

Depending on what your intentions are.

Comments

0
for u,v in [root]:
   print u,v

will do what you want.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.