更新时间:2022-01-25 05:00:30
您可以使用列表推导式:
You can use list comprehension:
strings = ["aString", "yetAnotherString", "evenAnotherOne"]
["String" in i for i in strings]
#Out[76]: [True, True, False]
或者使用re
模块:
import re
[bool(re.search("String", i)) for i in strings]
#Out[77]: [True, True, False]
或者使用 Pandas
(R 用户可能对此库感兴趣,使用类似"结构的数据框):
Or with Pandas
(R user may be interested in this library, using a dataframe "similar" structure):
import pandas as pd
pd.Series(strings).str.contains('String').tolist()
#Out[78]: [True, True, False]