我是python的新手。我有一个 在 在上面的字典的 请注意,“州”是指所有国家,而不仅仅是印度。 我不怎么找它。 python中是否有任何州和国家/地区的资料库,我可以将资料与资料库配对?我知道 为我提供一些解决此问题的解决方案。 这是我尝试的代码: 必需的输出:dict
,看起来像这样。 a = {'StartupName': 'FPL Technologies', 'coun': 'India', 'stat': 'Punjab', 'Amount': 4500000}
dict
中,我想将country_type
和state_type
,int_type
和all_type
作为单独的列表。coun
键中,具有国家名称,在stat
键中,具有状态名称。
程序应检查字典中的值是否具有country name
,然后应将具有国家/地区值的键附加到country_type
列表中。
如果字典中的值具有state name
,则应将具有状态值的键附加到state_type
列表中。 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']
0 个答案:
没有答案