如何从字符串中的共同元素中创建字典

发布于 2025-01-24 10:03:02 字数 675 浏览 0 评论 0原文

我需要从具有相同第一个字符的字符串中的所有秒字符。

这是我的代码:

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'}

预先感谢您!

I need to put all the seconds character from a string that have the same first character in common.

This is my code:

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'])

output:

GALA BSC
GALA ETH
VIB ETH
FIS BSC
FIS ETH
BAR CHZ
RAD ETH
COTI BSC
COTI BNB
COTI ETH

but i need to transform it in a dictionary like this:

GALA = {'BSC', 'ETH'}
VIB = {'ETH'}
FIS = {'BSC', 'ETH'}
BAR = {'CHZ'}
RAD = {'ETH'}
COTI = {'BSC', 'BNB', 'ETH'}

thank you in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榕城若虚 2025-01-31 10:03:02

尝试以下操作:

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)

Try this:

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文