Delete Extra Space from Values In List

前端 未结 3 548
礼貌的吻别
礼貌的吻别 2021-01-17 04:37

I have a list of numbers in Python all with a extra space in the front. How do I remove the extra space (so that only the numbers are left)? A short example is below (note

3条回答
  •  Happy的楠姐
    2021-01-17 04:58

    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.

提交回复
热议问题