提供了字典:
somedictionary = {"a":["b","c","d"],"1":["2","3"]}
如何创建单独的列表,使['a', 'b', 'c', 'd']
和['1', '2', '3']
是两个单独的列表?我的麻烦是遍历键值列表。
答案 0 :(得分:2)
您可以使用items
w_dict = {"a":["b","c","d"],"1":["2","3"]}
lists = [[k] + v for k,v in w_dict.items()]
产量:
[['a', 'b', 'c', 'd'], ['1', '2', '3']]