Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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_Python 3.x - Fatal编程技术网

Python 从列表中删除字符

Python 从列表中删除字符,python,python-3.x,Python,Python 3.x,我花了几个小时试图解决这个问题,但还没有找到解决方案(同样在SE上)。 我的问题如下: 我通过Beautifulsoup解析一个HTML表,创建了一个列表,它提供了以下信息: results = [[None, ' Windows 64 bit\n\t\t'], ['\n\t Official\n\t'], ['blender-2.76-3f602ff-win64.zip'], ['108M'], ['\n\t Thu Feb 25 09:21:53 2016\n\t'], [None,

我花了几个小时试图解决这个问题,但还没有找到解决方案(同样在SE上)。 我的问题如下: 我通过Beautifulsoup解析一个HTML表,创建了一个列表,它提供了以下信息:

results = [[None, ' Windows 64 bit\n\t\t'], ['\n\t   Official\n\t'], ['blender-2.76-3f602ff-win64.zip'], ['108M'], ['\n\t  Thu Feb 25 09:21:53 2016\n\t'], [None, ' Mac OS X 64 bit\n\t   \t\t'], ['\n\t   Official\n\t'], ['blender-2.76-ba98b68-OSX-10.6-x86_64.zip'], ['113M'], ['\n\t  Thu Feb 25 09:57:40 2016\n\t'], [None, ' Windows 32 bit\n    \t'], ['\n\t   Official\n\t'], ['blender-2.76-ba98b68-win32.zip'], ['90M'], ['\n\t  Thu Feb 25 11:33:10 2016\n\t'], [None, ' Linux 32 bit\n\t   \t\t'], ['\n\t   Official\n\t'], ['blender-2.76-3f602ff-linux-glibc211-i686.tar.bz2'], ['106M'], ['\n\t  Thu Feb 25 08:33:43 2016\n\t'], [None, ' Linux 64 bit\n\t   \t\t'], ['\n\t   Official\n\t'], ['blender-2.76-3f602ff-linux-glibc211-x86_64.tar.bz2'], ['108M'], ['\n\t  Thu Feb 25 08:33:24 2016\n\t'], ['\xa0\n'], ['\xa0\n'], ['\xa0\n'], ['\xa0\n'], ['\xa0\n']]

现在我想删除\n和\t字符、空格和\xa0\n最后出现的内容。我尝试通过
results=list(map(str.strip,results))
映射列表,但没有任何变化,列表保持原样。 我是Python新手,即使在这里看了其他示例之后,我也没有发现任何适合我的东西。 提前谢谢

试试这个:

results = [[item.strip().strip("\xa0") if item is not None else None for item in sublist] for sublist in results]

“我想删除\n和\t字符,空格…”这样可以工作,但是您的
条带对于OP的情况来说太窄了。您是什么意思?我用
.strip()
删除所有空白,然后用
.strip(“\xa0”)
删除
“\xa0”
。缺少什么?对不起,我读得太快了,我的大脑跳过了重复的脱衣舞。继续:)@tobkum:很高兴能帮忙。(尤其是当我因为它获得了55%的声誉时:)