0

I am extracting a dictionary that's giving me this output:

mylist= [[u'Ann', u'jOhn', u'Clive'], [u'124street', u'32B', u'16eve', u'beach']]

When I try to separate it into two, I get a ValueError:

nest1, nest2 = zip(*mylist)

ValueError: too many values to unpack

Ultimately I need something like this:

nest1=['Ann', 'jOhn', 'Clive']
nest2=['124Street', '32B', '16eve', 'beach]

I found zip(*mylist) within this answer.

Tagc
  • 8,736
  • 7
  • 61
  • 114
Ahsan Naseem
  • 1,046
  • 1
  • 19
  • 38

2 Answers2

5

*zip is meant to be used to unpack lists of tuples. In your case, there is no unpacking needed to be done, so just unpack the list itself:

In [473]: x, y = [[u'Ann', u'jOhn', u'Clive'], [u'124street', u'32B', u'16eve', u'beach']]

In [474]: x
Out[474]: ['Ann', 'jOhn', 'Clive']

In [475]: y
Out[475]: ['124street', '32B', '16eve', 'beach']
cs95
  • 379,657
  • 97
  • 704
  • 746
0

Try this

mylist= [[u'Ann', u'jOhn', u'Clive'], [u'124street', u'32B', u'16eve', u'beach']]
nest1 = mylist[0]
nest2 = mylist[1]
print("nest1={}".format(nest1))
print("nest2={}".format(nest2))

Outputs:

nest1=['Ann', 'jOhn', 'Clive']
nest2=['124street', '32B', '16eve', 'beach']