I am trying to get my head around this for hours, but haven't found a solution yet (also here on SE). My problem is as follows: I created a list by parsing a HTML table via Beautifulsoup, which gives me the following:
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']]
Now I want to remove the \n and \t characters, the whitespace and the \xa0\n occurrences in the end. I tried mapping the list via results = list(map(str.strip, results)), but nothing changes, the list stays as it is.
I'm new to Python, even after looking at other examples on here I didn't find anything that worked for me.
Thanks in advance!
Try this:
results = [[item.strip().strip("\xa0") if item is not None else None for item in sublist] for sublist in results]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With