Python 如何读取列表中的多个值?
我需要一个函数来读取列表并查找字母序列。如果它发现他们打印一些东西Python 如何读取列表中的多个值?,python,list,for-loop,Python,List,For Loop,我需要一个函数来读取列表并查找字母序列。如果它发现他们打印一些东西 lst = ['T','T','T','S','S','S','T','T'] match = False strS = "S S S" for item in lst: if item in strS: match = True if match: print("Fail") 这不起作用
lst = ['T','T','T','S','S','S','T','T']
match = False
strS = "S S S"
for item in lst:
if item in strS:
match = True
if match:
print("Fail")
这不起作用,因为有很多列表具有不同的T和s组合。我希望它只在连续有三个S的情况下才起作用,并且它还可以读取任何其他S和打印
big_str = ' '.join(lst)
found = strS in big_str
第一条语句使用空格作为分隔符,使单个字符串构成字母列表。第二条语句检查搜索字符串是否在大字符串中,并将结果存储在found
中。您现在可以返回或打印找到的