我有一個看起來像這樣的列表:Python的迭代只要元素在列表中存在整數
data = [['info', 'numbers', 'more info'], ['info', 'numbers', 'more info'], ['..*this is dynamic so it could have hundreds*..']]
data
從一個動態的文件中讀取和分裂是這樣的,所以數量的元素是未知的。
我想要做的是重新加入項目之間的信息與':'
並將其存儲到每行文本文件,但問題是循環遍歷數據元素並增加一個整數用於數據列表。
這裏是一個片段:
#not sure what type of loop to use here
# to iterate through the data list.
saveThis = ':'.join(data[n])
file2.write(saveThis+'\n')
感謝
對於數據中的子列表: file2.write('..... ..') 完美運作。非常感謝你,這正是我想要做的。我仍然知道python遠遠優於C++ – user2407199