2024-10-04 03:15:58 发布
网友
[['\nAabhas\n'], ['\n\nThe sense, Feelings (1)\n\n'], ['\n5\n'], ['\nBoy\n'], ['\n\n']
在此列表中,[]之间的值应作为一列中的值。你知道吗
使用strip()
strip()
>>> l = '\nAabhas\n' >>> l.strip() 'Aabhas' >>>
使用strip是最好的方法,我认为regex很昂贵-
strip
regex
lst = [['\nAabhas\n'], ['\n\nThe sense, Feelings (1)\n\n'], ['\n5\n'], ['\nBoy\n'], ['\n\n']] corrected_list = [] for i in lst: intm = [] for j in i: intm.append(j.strip()) corrected_list.append(intm) print corrected_list
或者使用一行列表理解-
[[j.strip() for j in i] for i in lst]
输出-
[['Aabhas'], ['The sense, Feelings (1)'], ['5'], ['Boy'], ['']]
使用
strip()
使用
strip
是最好的方法,我认为regex
很昂贵-或者使用一行列表理解-
输出-
相关问题 更多 >
编程相关推荐