Nested Dictionary formatted output issues

25 views Asked by At

I've the following nested dictionary:

[[u'bob', u'fred'], [u'sanders', u'harris'], [u'[email protected]', u'[email protected]'], ['user1 password', 'user2 password']]

Printing Key/Value I get:

1: bob
1: fred
2: sanders
2: harris
3: [email protected]
3: [email protected]
4: user1 password
4: user2 password

I cannot find a way in Python 2.7 to get the following output:

bob[tab]sanders[tab][email protected][tab]user1 password

fred[tab]harris[tab][email protected][tab]user2 password

Could you please assist me?

1

There are 1 answers

2
machnic On

This snippet should solve your problem:

mylist = [[u'bob', u'fred'], [u'sanders', u'harris'], [u'[email protected]', u'[email protected]'], ['user1 password', 'user2 password']]

for i in range(len(mylist[0])):
    print '%s\t%s\t%s\t%s' % (mylist[0][i], mylist[1][i], mylist[2][i], mylist[3][i])

Note that your "nested dictionary" is not a dictionary.