要做到这一点,如何比较两个不同的列数据,而不考虑不同文本文件中的顺序?
输入1(文本文件1)
ABCD, QI30
FGDE, Q140
KLOM, Q232
.. ..
.. ..
.. ..
输入2(文本文件2)
DATA: ARRAY: KLOM: n: 000000000111111110011111111111111111111111
DATA: ARRAY: ABCD: n: 000111111111111111101111111111111111111111
DATA: ARRAY: FGDE: n: 010101010111111111111111111111111111111111
.. ..
.. ..
.. ..
输出(写在文本文件中3)
Item=Q232; Var:KLOM
read_Var:read_q232: Get_Data: n: 000000000111111110011111111111111111111111
Item=Q130; Var:ABCD
read_Var:read_q150: Get_Data: n: 000111111111111111101111111111111111111111
Item=Q140; Var:FGDE
read_Var:read_q170: Get_Data: n: 010101010111111111111111111111111111111111
.. ..
.. ..
.. ..
这是代码的一部分,
import collections
#Create a data dict using textfile1.txt
with open("textfile1.txt") as f1:
# create generator of entries using non-empty lines in file
entries1 = (line.split() for line in f1 if line.strip())
# create dict using ($1) as key and $2 as value
data1 = dict(((d[0], d[1]) for d in entries1)
with open("textfile2.txt") as f2:
entries2 = (line.split() for line in f2 if line.strip())
data2 = dict(((f[2], f[3]), f[4]) for f2 in entries2)
set(d[1]) == set(f[2]) # compare the text file1 column 2 with text file2 column 3
此后,我不知道该怎么做。真的,我需要你们的帮助。
什么语言?它看起来像Python,但我不知道。如果您想让正确类型的程序员看到您的帖子,请使用正确的语言标记编辑您的帖子。 – Clay
Ya ya,它的Python语言@Clayton – Noorul
一个好的开始是解释你想要做什么,正确缩进你的代码,并确保右括号的数量等于左括号的数量。这些都还没有完成。 –