2024-10-06 15:29:16 发布
网友
我有两个城市和国家的名单。你知道吗
List1=['Athens', 'Sidney'] List2=['Greece', 'Australia'] c=raw_ input('Enter a city: ')
雅典在希腊,悉尼在澳大利亚。你知道吗
我怎样才能用列表而不是字典来测试西德尼是否在澳大利亚?你知道吗
zip两个列表,组成一个字典,检查悉尼钥匙!你知道吗
zip
myHash=dict(zip(List1, List2)) myHash.has_key("Sidney")
打印True如果存在,否则False
True
False
你可以这样做:
result = [country for city,country in zip(List1,List2) if city == c] if result: print('This city is in {}'.format(result[0])) else: print('City not found')
zip
两个列表,组成一个字典,检查悉尼钥匙!你知道吗打印
True
如果存在,否则False
你可以这样做:
相关问题 更多 >
编程相关推荐