回答編集履歴
1
d
test
CHANGED
@@ -45,3 +45,53 @@
|
|
45
45
|
print(jpy["amount"]) # 53727
|
46
46
|
|
47
47
|
```
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
## 追記
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
上記処理を関数化して利用できるようにすればいいと思います。
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```python
|
60
|
+
|
61
|
+
import json
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
with open("sample.json") as f:
|
66
|
+
|
67
|
+
balance = json.load(f)
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
def get_data(balance, symbol):
|
74
|
+
|
75
|
+
return next(filter(lambda x: x["symbol"] == symbol, balance["data"]))
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
jpy = get_data(balance, "JPY")
|
82
|
+
|
83
|
+
print(jpy)
|
84
|
+
|
85
|
+
print(jpy["amount"]) # 53727
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
btc = get_data(balance, "BTC")
|
92
|
+
|
93
|
+
print(btc)
|
94
|
+
|
95
|
+
print(btc["amount"]) # 53727
|
96
|
+
|
97
|
+
```
|