Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am getting the 'too many values to unpack' error. Any idea how I can fix this?

first_names = ['foo', 'bar'] 

last_names = ['gravy', 'snowman'] 

fields = { 

'first_names': first_names, 

'last_name': last_names, 

for field, possible_values in fields: # error happens on this line

2 Answers

0 votes
by (106k points)

You need to use something iteritems.

for field, possible_values in fields.iteritems(): 

print(field, possible_values)

0 votes
by (20.3k points)

You can try using something like iteritems.

for field, possible_values in fields.iteritems():

   print field, possible_values

If you are working on Python 3 try using items() instead of using iteritems().

for field, possible_values in fields.items():

    print(field, possible_values)

Related questions

0 votes
1 answer
asked Aug 26, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
asked Jul 25, 2019 in Python by Eresh Kumar (45.3k points)
+1 vote
1 answer
asked Jul 5, 2019 in Python by selena (1.6k points)
0 votes
1 answer
asked Oct 11, 2019 in Python by Sammy (47.6k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...