回答編集履歴
1
見やすく
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
|
+
```
|