【问题标题】:How to separate a String inside the list into Sub string without create a new list in python如何在不在python中创建新列表的情况下将列表中的字符串分成子字符串
【发布时间】:2020-05-14 16:02:03
【问题描述】:

我有 python 列表,

l=['wright_2035566_qwerty , wright_2035566_qwerty,wright_2035566_qwerty']

但我需要将此列表转换为 python 所需列表中的格式

new_list=['wright_2035566_qwerty', 'wright_2035566_qwerty', 'wright_2035566_qwerty']

请帮帮我

【问题讨论】:

    标签: python string list loops split


    【解决方案1】:

    或使用:

    new_list = list(map(str.strip, l[0].split(',')))
    

    【讨论】:

      【解决方案2】:

      我希望这对你有用:

      new_list = [x.strip() for x in l[0].split(',')]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-24
        • 2017-10-21
        • 1970-01-01
        • 2020-04-21
        • 2011-07-14
        • 1970-01-01
        • 2022-10-14
        相关资源
        最近更新 更多