python: iterating through a dictionary with list values

前端 未结 4 2141
时光说笑
时光说笑 2020-12-08 10:18

Given a dictionary of lists, such as

d = {\'1\':[11,12], \'2\':[21,21]}

Which is more pythonic or otherwise preferable:

fo         


        
4条回答
  •  一生所求
    2020-12-08 10:26

    Here's the list comprehension approach. Nested...

    r = [[i for i in d[x]] for x in d.keys()]
    print r
    
    [[11, 12], [21, 21]]
    

提交回复
热议问题