-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