检查一个列表的一项是否存在于另一个字符串列表中

时间:2021-07-27 06:15:37

标签: python python-3.x list

我正在检查 state_list 中的州名称是否存在于 address 列表中。我尝试了以下方法,但没有用。

state_list = ['VIC', 'WA']
address = ['Unit 6, Traeger Court Business Park 28 Thynne', 'Street', 'BRUCE, ACT, 2617', 'AUSTRALIA']

for state in state_list:
    for a in address:
        if state in a:
            print(state)

2 个答案:

答案 0 :(得分:1)

'VIC' 'WA'

它们都不在您的地址列表中

答案 1 :(得分:0)

你的代码看起来不错。您在地址列表中没有任何地址具有状态列表中的任何状态。添加一个包含 state_list 中的 state 的新地址并再次检查