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,我有一个python列表,其中包含像['abc'、'defg',xyz'、'lmnopqrst']这样的字符串。我需要遍历列表并提取第2和第3位置的元素,然后创建另一个仅包含这些字母的列表 例如:O/P应该是一个有['bc'、'ef'、'yz'、'mn']的列表 output_list = [s[1:3] for s in input_list] 您可以这样做: new_list = [ s[1:3] for s in your_list ] 请发布一些代码,并正式说明问题到底出在哪里。这些

我有一个python列表,其中包含像['abc'、'defg',xyz'、'lmnopqrst']这样的字符串。我需要遍历列表并提取第2和第3位置的元素,然后创建另一个仅包含这些字母的列表 例如:O/P应该是一个有['bc'、'ef'、'yz'、'mn']的列表

output_list = [s[1:3] for s in input_list]
您可以这样做:

new_list = [ s[1:3] for s in your_list ]

请发布一些代码,并正式说明问题到底出在哪里。这些字母我指的是第二位和第三位的字母。当你说字母时,我想你指的是字母。道歉。我的意思是字母作为后续,如果列表如下所示:['abc','1234','defg','xyz','6898','lmnopq']我只想要以下列表作为我的O/P:['bc','ef','yz','mn']