1
我有這個交錯兩個單詞並輸出新的交錯單詞作爲元組的代碼,但我也需要它是一個原始字符串。將一個列表格式化爲一個字符串Python
from itertools import zip_longest
def interleave(word1,word2):
return ''.join(list(map(str, zip_longest(word1,word2,fillvalue=''))))
如果輸入的話,貓和帽子,這個輸出
('h', 'c')('a', 'a')('t', 't').
但我需要它輸出
hcaatt
我怎麼能去格式化這個名單成一個正常的字符串
參見[製作一個平面列表出Python列表的列表(HTTPS:/ /stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python) – cowbert