中有什麼我有2個csv文件,我想比較其中之一是所有國家的主文件,然後是另一個只有少數幾個國家。這是一個試圖爲一些基本的測試中,我提出:比較python中的csv文件,看看在
char = {}
with open('all.csv', 'rb') as lookupfile:
for number, line in enumerate(lookupfile):
chars[line.strip()] = number
with open('locations.csv') as textfile:
text = textfile.read()
print text
for char in text:
if char in chars:
print("Country found {0} found in row {1}".format(char, chars[char]))
我試圖讓國家的主文件的最終輸出與指示次級柱,如果它在其他列表上來
謝謝!
當你需要毫無價值詞典,使用套... –
林相當新的Python,所以我將不得不作出在csv文件的一切的關鍵像你已經顯示的變量一樣? – Gaddi
如果你只是比較國家,那麼你只需要爲國家制作鑰匙。字典[國家] =真。 @EricLevieil集合的問題是查找的最壞情況是O(n)。 –