Shortest way to get first item of `OrderedDict` in Python 3

后端 未结 6 990
庸人自扰
庸人自扰 2020-12-24 05:01

What\'s the shortest way to get first item of OrderedDict in Python 3?

My best:

list(ordered_dict.items())[0]

Quite lo

6条回答
  •  时光说笑
    2020-12-24 05:24

    First record:

    [key for key, value in ordered_dict][0]
    

    Last record:

    [key for key, value in ordered_dict][-1]
    

提交回复
热议问题