Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何读取列表中的多个值?_Python_List_For Loop - Fatal编程技术网

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
中。您现在可以返回或打印找到的