How do you join all items in a list?

后端 未结 4 1531
-上瘾入骨i
-上瘾入骨i 2020-12-05 15:45

I have a list and it adds each letter of a word one by one to this list, I don\'t know what will be in the list until the program is run. How do I join each letter in the li

相关标签:
4条回答
  • 2020-12-05 15:58
    a = ['a', 'b', 'c']
    res = "".join(a)
    

    You can again convert back to list of letters using :

    list(res)
    
    0 讨论(0)
  • 2020-12-05 15:59

    ''.join(['p','y','t','h','o','n'])

    For more information see str.join

    0 讨论(0)
  • 2020-12-05 16:07
    ''.join(str(v) for v in my_list)
    

    Since you do not know what will be in the list

    0 讨论(0)
  • 2020-12-05 16:08
      s=""
      for v in [['p', 'y', 't', 'h', 'o', 'n']:
             s+=v
      res=[s]
    
    0 讨论(0)
提交回复
热议问题