Delete Extra Space from Values In List

懵懂的女人 提交于 2019-12-01 14:37:50

Use str.lstrip here, as the white-space is only at the front:

List = [s.lstrip() for s in List]
# ['5432', '23421', '43242', ...]

Or in this case, seeing as you know how many spaces there are you can just do:

List = [s[1:] for s in List]

For your case, with a list, you can use str.strip()

l = [x.strip() for x in List]

This will strip both trailing and leading spaces. If you only need to remove leading spaces, go with Alex' solution.

map(str.strip, List)

or

map(lambda l: l.strip(), List)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!