-1
我有一個腳本,從2檔python腳本找出獨特的價值
1.csv
11 12 13 14
21 22 23 24
11 32 33 34
2.csv
41 42 43 44 45
51 52 53 54 55
41 62 63 64 65
腳本是找到獨特的價值:
import csv
import sys
# Count all first-column numbers.
counts = {}
# Loop over all input files.
for a in sys.argv[1:]:
# Open the file for reading.
with open(a) as c:
# Read it as a CSV file.
reader = csv.reader(c, delimiter=' ')
for row in reader:
count = counts.get(row[0], 0)
# Increment the count by 1.
counts[row[0]] = count + 1
# Print only those numbers that have a count of 1.
print([i for i, c in counts.items() if c == 1])
用法:
$ python 1.py 1.csv 2.csv
輸出
['51', '21']
,但我想不同的行輸出像
51
21
我該如何在代碼中實現這一點? – praneethng
謝謝你 – praneethng