我对Python还不熟悉。我有一个dict
看起来像这样。你知道吗
a = {'StartupName': 'FPL Technologies', 'coun': 'India', 'stat': 'Punjab', 'Amount': 4500000}
在dict
中,我想将country_type
和state_type
、int_type
和all_type
作为一个单独的列表。你知道吗
在上述dict的coun
键中,它有国家名称,在stat
键中,它有州名称。
程序应该检查dict中的值是否具有country name
,然后应该将具有country值的键附加到country_type
列表中。
如果dict中的值有一个state name
,那么它应该将具有状态值的键附加到state_type
列表中。你知道吗
请注意,“国家”是指所有国家,而不仅仅是印度。你知道吗
我不知道怎么取回它。有没有python中的州和国家的库,我可以用它来匹配数据?我知道pycountry
库,但我不知道州。你知道吗
帮我找到一些解决这个问题的办法。你知道吗
以下是我尝试的代码:
a = {'StartupName': 'FPL Technologies', 'coun': 'India', 'stat': 'Punjab', 'Amount': 4500000}
all_type = []
country_type = []
state_type = []
int_type=[]
for i in a:
print(i)
if type(a[i]) == type(0):
int_type.append(i)
print("Int Type:", int_type)
print("Country Type:",country_type)
print("State Type:",state_type)
print("All Type:",all_type)
所需输出:
Int Type: ['Amount']
Country Type: ['coun']
State Type: ['stat']
All Type: ['StartupName','coun','stat,'Amount']
目前没有回答
相关问题 更多 >
编程相关推荐