【发布时间】:2019-04-02 13:22:43
【问题描述】:
我正在编写一个脚本,其目标是检查每个国家/地区 (country) 并根据索引是否存在 supply 列表中的条目。目标是打印出每个国家/地区的条目是否存在。
国家:
country=['usa', 'poland', 'australia', 'china']
用于检查country 中的每个项目到supply 的索引。
# index
water_country=water_<country>_country
gas_state=gas_<country>_state
oil_city=oil_<country>_city
供应:
supply=['water_usa_country', 'gas_usa_state', 'oil_usa_city', 'water_poland_country', 'gas_poland_city', 'gas_australia_state']
对于上述情况,结果将出现在每个国家/地区的列表中:
For country 'usa' all entries exist
For country 'poland' following entries does not exist:
oil_poland_city
For country 'australia' following entries does not exist:
water_australia_country
oil_australia _city
For country 'china' following entries does not exist:
water_china_country
gas_china_state
oil_china_city
【问题讨论】:
-
为什么首先将此类信息存储为字符串?这看起来像是
dicts的工作,命名为元组甚至是类。
标签: python python-3.x python-2.7 list compare