Python - match a word in a string with a list of strings

后端 未结 6 2196
北恋
北恋 2021-01-25 22:20

I\'m new to python and I was wondering how string comparison is done

Let\'s say I have a list of strings containing state names like

states = [\"New York         


        
6条回答
  •  既然无缘
    2021-01-25 22:34

    To find all matches in the string you could do:

    matches = [m for m in postal_addr.split() if m in states]
    

提交回复
热议问题