3
辞書項目の順序が信頼できるで作成されます?ディクショナリ項目の順序は作成時に信頼できる**ですか?
注:これは人々はdict
がOrderedDict
のように振る舞うことを期待し、すべての質問の重複ではありません。
私がしたいことは、json辞書をAWSラムダ関数に渡すことです。その辞書の内容の多くは、open
ファイルハンドラから得られます。
params = {
"FunctionName": "log_load",
"Payload": json.dumps({
"header": fh.readline(),
"start": fh.tell(),
"data": fh.read(),
"end": fh.tell()})}
result = lambda_client.invoke(**params)
それはfh
オブジェクト上でこれらのメソッドのすべてがは、彼らがリストされている順序でと呼ばれることが重要です。それはこのような何かを行きます。私はそれが後で読み込まれるときに辞書の順番に気にしない。
リストされている順番で呼び出されている4つの関数に依存することはできますか?
以下のテストを作成しました。これは、できる限りの事例を示してくれます。しかし、pprintがディクショナリを順不同で表示するケースもありません。だから、私はキーが値と一致することに驚くことはありません。
from pprint import pprint
r = range(100)
i = r.__iter__()
d = {
0: i.__next__(),
1: i.__next__(),
2: i.__next__(),
3: i.__next__(),
4: i.__next__(),
5: i.__next__(),
6: i.__next__(),
7: i.__next__(),
8: i.__next__(),
9: i.__next__(),
10: i.__next__(),
11: i.__next__(),
12: i.__next__(),
13: i.__next__(),
14: i.__next__(),
15: i.__next__(),
16: i.__next__(),
17: i.__next__(),
18: i.__next__(),
19: i.__next__(),
20: i.__next__(),
21: i.__next__(),
22: i.__next__(),
23: i.__next__(),
24: i.__next__(),
25: i.__next__(),
26: i.__next__(),
27: i.__next__(),
28: i.__next__(),
29: i.__next__(),
30: i.__next__(),
31: i.__next__(),
32: i.__next__(),
33: i.__next__(),
34: i.__next__(),
35: i.__next__(),
36: i.__next__(),
37: i.__next__(),
38: i.__next__(),
39: i.__next__(),
40: i.__next__(),
41: i.__next__(),
42: i.__next__(),
43: i.__next__(),
44: i.__next__(),
45: i.__next__(),
46: i.__next__(),
47: i.__next__(),
48: i.__next__(),
49: i.__next__(),
50: i.__next__(),
51: i.__next__(),
52: i.__next__(),
53: i.__next__(),
54: i.__next__(),
55: i.__next__(),
56: i.__next__(),
57: i.__next__(),
58: i.__next__(),
59: i.__next__(),
60: i.__next__(),
61: i.__next__(),
62: i.__next__(),
63: i.__next__(),
64: i.__next__(),
65: i.__next__(),
66: i.__next__(),
67: i.__next__(),
68: i.__next__(),
69: i.__next__(),
70: i.__next__(),
71: i.__next__(),
72: i.__next__(),
73: i.__next__(),
74: i.__next__(),
75: i.__next__(),
76: i.__next__(),
77: i.__next__(),
78: i.__next__(),
79: i.__next__(),
80: i.__next__(),
81: i.__next__(),
82: i.__next__(),
83: i.__next__(),
84: i.__next__(),
85: i.__next__(),
86: i.__next__(),
87: i.__next__(),
88: i.__next__(),
89: i.__next__(),
90: i.__next__(),
91: i.__next__(),
92: i.__next__(),
93: i.__next__(),
94: i.__next__(),
95: i.__next__(),
96: i.__next__(),
97: i.__next__(),
98: i.__next__(),
99: i.__next__()}
pprint(d, width=-1, indent=4)
ありがとうございました。それは私がグーグルグーグルで見つけられなかったもの。私は5分後にあなたの答えを受け入れてくれます。あなたはブザーを叩いた。 –