回答編集履歴

1

見やすく

2018/10/04 08:01

投稿

LouiS0616
LouiS0616

スコア35660

test CHANGED
@@ -6,4 +6,32 @@
6
6
 
7
7
  コードに意味を持たせるという観点で[OrderedDict](https://docs.python.jp/3/library/collections.html#collections.OrderedDict)を使うことをお勧めします。
8
8
 
9
+
10
+
9
11
  OrderedDictのメソッドpopitemを用いれば、FIFOあるいはLIFOで値のペアを取得できます。
12
+
13
+ ```Python
14
+
15
+ >>> from collections import OrderedDict
16
+
17
+ >>>
18
+
19
+ >>> o_dct = OrderedDict(one=1, two=2, three=3)
20
+
21
+ >>> o_dct.popitem()
22
+
23
+ ('three', 3)
24
+
25
+ >>>
26
+
27
+ >>> o_dct.popitem(last=False)
28
+
29
+ ('one', 1)
30
+
31
+ >>>
32
+
33
+ >>> o_dct
34
+
35
+ OrderedDict([('two', 2)])
36
+
37
+ ```