create ordered dict from list comprehension?

后端 未结 2 933
孤城傲影
孤城傲影 2021-02-20 12:19

Here is a list comprehension:

L = [{k: d[k](v) for (k, v) in l.iteritems()} for l in L]

where

  • L is a list of or

2条回答
  •  故里飘歌
    2021-02-20 13:05

    collections.OrderedDict is nothing but a dict, which remembers the order in which the elements are included in it. So you can create one with its constructor like this

    [OrderedDict((k, d[k](v)) for (k, v) in l.iteritems()) for l in L]
    

提交回复
热议问题