您好,我目前正在从网上抓取信息并将其放入列表中,但是元素显示为:
['\n Michael\n ',
'\n Elad\n ',
'\n Yair\n ',
'\n Liron\n ',
'\n Idan\n ',
'\n Tomer\n ',
'\n Ofer\n ',
'\n Asaf\n ',
'\n Tomer\n ',
'\n Ronit\n ',
'\n Guy\n ',
'\n Lior\n ']
是否可以格式化列表以消除行缩进和空白?
谢谢
答案 0 :(得分:0)
使用.strip()
方法:
>>> l = ['\n Michael\n ', '\n Elad\n ']
>>> l
['\n Michael\n ', '\n Elad\n ']
>>> [x.strip() for x in l]
['Michael', 'Elad']