質問するログイン新規登録

回答編集履歴

1

見やすく

2018/10/04 08:01

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -2,4 +2,18 @@
2
2
 
3
3
  Python3.7以降、あるいはCPython3.6以降なら可能ですが、
4
4
  コードに意味を持たせるという観点で[OrderedDict](https://docs.python.jp/3/library/collections.html#collections.OrderedDict)を使うことをお勧めします。
5
+
5
- OrderedDictのメソッドpopitemを用いれば、FIFOあるいはLIFOで値のペアを取得できます。
6
+ OrderedDictのメソッドpopitemを用いれば、FIFOあるいはLIFOで値のペアを取得できます。
7
+ ```Python
8
+ >>> from collections import OrderedDict
9
+ >>>
10
+ >>> o_dct = OrderedDict(one=1, two=2, three=3)
11
+ >>> o_dct.popitem()
12
+ ('three', 3)
13
+ >>>
14
+ >>> o_dct.popitem(last=False)
15
+ ('one', 1)
16
+ >>>
17
+ >>> o_dct
18
+ OrderedDict([('two', 2)])
19
+ ```