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 - Fatal编程技术网

Python另一个嵌套列表

Python另一个嵌套列表,python,list,Python,List,通过搜索列表中的特定单词,将每个子列表分成另一个子列表。这是我的密码: for i in list_1: for x in i: regex = re.compile(r '^pft') matched = filter(regex.search ,x) print(matched) list_1 = [['MP1 Z A VDD VNW pft\n', 'MN1 Z A VSS VPW nft\n'], ['MM19

通过搜索列表中的特定单词,将每个子列表分成另一个子列表。这是我的密码:

for i in list_1:
      for x in i:
          regex = re.compile(r '^pft')
          matched = filter(regex.search ,x)
          print(matched)

list_1 = [['MP1 Z A VDD VNW pft\n', 'MN1 Z A VSS VPW nft\n'],
 ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n', 'MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']]
如果子列表元素是pft作为一个列表,nft作为一个组,那么我只需要grep列表的一个元素,并从列表的第一个元素中再生成两个列表

例如:

list_2 = ['MP1 Z A VDD VNW pft\n', 'MN1 Z A VSS VPW nft\n']    
pft_list = ['MP1 Z A VDD VNW pft\n']
nft_list = ['MN1 Z A VSS VPW nft\n']
同样地

list_3 = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n', 'MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']
pft_list = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n']
nft_list = ['MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']
list_3 = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n', 'MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']
pft_list = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n']
nft_list = ['MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']
例如:

list_2 = ['MP1 Z A VDD VNW pft\n', 'MN1 Z A VSS VPW nft\n']
pft_list = ['MP1 Z A VDD VNW pft\n']
nft_list = ['MN1 Z A VSS VPW nft\n']
同样地

list_3 = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n', 'MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']
pft_list = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n']
nft_list = ['MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']
list_3 = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n', 'MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']
pft_list = ['MM19 Z A VDD VNW pft\n', 'MM18 Z A VDD VNW pft\n', 'MM17 Z A VDD VNW pft\n', 'MM16 Z A VDD VNW pft\n', 'MM15 Z A VDD VNW pft\n', 'MM14 Z A VDD VNW pft\n', 'MM13 Z A VDD VNW pft\n', 'MM12 Z A VDD VNW pft\n', 'MM11 Z A VDD VNW pft\n', 'MM10 Z A VDD VNW pft\n']
nft_list = ['MM9 Z A VSS VPW nft\n', 'MM8 Z A VSS VPW nft\n', 'MM7 Z A VSS VPW nft\n', 'MM6 Z A VSS VPW nft\n', 'MM5 Z A VSS VPW nft\n', 'MM4 Z A VSS VPW nft\n', 'MM3 Z A VSS VPW nft\n', 'MM2 Z A VSS VPW nft\n', 'MM1 Z A VSS VPW nft\n', 'MM0 Z A VSS VPW nft\n']

从您的示例中,似乎您只想过滤分别以
pft
nft
结尾的元素。您可以通过简单的列表理解来实现

pft_list = [x for x in list_3 if x.strip().endswith("pft")]             
nft_list = [x for x in list_3 if x.strip().endswith("nft")]             
或者如果x.endswith(“pft\n”)的
,如果
\n
始终是字符串的一部分。这将产生与预期输出相同的结果。不确定第一部分是否包含嵌套列表,但您可以将其应用于子列表。请注意,正则表达式
^pft
将检查字符串是否以
pft
开头