我需要從具有相同第一個字符的字串中放入所有秒字符。
這是我的代碼:
Coin_Info = Binance_Client.get_all_coins_info()
for n in Coin_Info:
Coin, Net = n['coin'], n['networkList']
for e in Net:
if e['depositEnable'] and e['withdrawEnable'] is True:
print(Coin, e['network'])
輸出:
GALA BSC
GALA ETH
VIB ETH
FIS BSC
FIS ETH
BAR CHZ
RAD ETH
COTI BSC
COTI BNB
COTI ETH
但我需要像這樣在字典中轉換它:
GALA = {'BSC', 'ETH'}
VIB = {'ETH'}
FIS = {'BSC', 'ETH'}
BAR = {'CHZ'}
RAD = {'ETH'}
COTI = {'BSC', 'BNB', 'ETH'}
先感謝您!
uj5u.com熱心網友回復:
試試這個:
my_dict = {}
Coin_Info = Binance_Client.get_all_coins_info()
for n in Coin_Info:
Coin, Net = n['coin'], n['networkList']
for e in Net:
if e['depositEnable'] and e['withdrawEnable']:
if not my_dict.hasKey(Coin):
my_dict[Coin] = []
my_dict[Coin].append(e['network'])
print(my_dict)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/465134.html
下一篇:將物件轉換為字典鍵
