0

我有以下嵌套字典:

[[u'bob', u'fred'], [u'sanders', u'harris'], [u'bob@xyz.com', u'fredharris@abc.com'], ['user1 password', 'user2 password']]

打印我得到的键/值:

1:bob
1:fred
2:sanders
2:harris
3:bob@xyz.com
3:fredharris@abc.com
4:user1 密码
4:user2 密码

我在Python 2.7中找不到获得以下输出的方法:

bob[tab]sanders[tab]bob@xyz.com[tab]user1 password

fred[tab]harris[tab]fredharris@abc.com[tab]user2 password

你能帮帮我吗?

4

1 回答 1

0

此代码段应该可以解决您的问题:

mylist = [[u'bob', u'fred'], [u'sanders', u'harris'], [u'bob@xyz.com', u'fredharris@abc.com'], ['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])

请注意,您的“嵌套字典”不是字典。

于 2019-10-02T15:45:10.457 回答