將一維列表的元素合併爲一個字符串

現有一個列表:python

  1. list = ["h","e","l","l","o"]  

須要將列表裏的全部元素合併爲一個字符串 「hello」,Python沒有內置函數能夠將列表的全部元素鏈接起來,相似於String的join函數。能夠採用另外一種方法函數

    import itertools  
  1. >>> s = "".join(itertools.chain(*list))  
  2. >>> s  
  3. s = "hello"  
相關文章
相關標籤/搜索