4Manuals

  • PDF Cloud HOME

从字典中获取国家和州? Download

    如何将文本边界框与pyplot.Rectangle对齐? 导入类问题 在Python数据框中选择列时出错 使用Rabbit的pika确认消息 如何在按住键的同时暂停VideoStream? Python OpenCV 将我的代码从多处理更改为普通 TypeError:无法处理此数据类型 使用buildozer不会下载sdl2_image 如何从作为请求传递的输入类型数据绑定中提取数据 SMTPSenderRefused,421,超出超时

我是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列表中。

请注意,“州”是指所有国家,而不仅仅是印度。

我不怎么找它。 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']

0 个答案:

没有答案



Similar searches
    react-boostrap和react-router导致整页重新加载 当两个应用程序同时访问一个localspark会话实例时发生错误。调用o2402.defaultParallelism时发生错误 Samsung RT37MA Refrigerator User Manual 根据SQL中的条件获取特定记录 如何通过其自动生成的ID订购文档? (Cloud Firestore)