分享
三行代码  ›  专栏  ›  技术社区  ›  Sbstyn

如何将列表中的python字符串转换为拆分的字符串[closed]

  •  -3
  • Sbstyn  · 技术社区  · 6 天前

    ['wordone','word2','worD'] 我怎样才能让它看起来像: [['w','o','r','d','o','n','e'],['w','o','r','d','2'],['w','o','r','D']]

    1 回复  |  直到 6 天前
        1
  •  3
  •   Have a nice day    6 天前

    我们可以这样做:

    lst = ['wordone','word2','worD']
    
    new_lst = [[letter for letter in word]for word in lst]
    
    print(new_lst)
    # output: [['w', 'o', 'r', 'd', 'o', 'n', 'e'], ['w', 'o', 'r', 'd', '2'], ['w', 'o', 'r', 'D']]
    
    
        2
  •  0
  •   tbjorch    6 天前

    words = ['wordone','word2','worD']
    new_list = [list(word) for word in words]
    print(new_list)