Cat Standart
1
2
3
5
Cat Node1.txt
1
2
5
6
Cat Node2.txt
1
2
3
4
5
6
Cat Node3.txt
1
7
8
9
The desired output results are:
Node1:3
Node2:
Node3:2 3 5
#!/usr/bin/python# -*- coding:utf-8 -*-def diff (x, y): list_x = [] list_y = [] file = open (x, ' R ') for line in file.readlines (): line = line.strip (' \ n ') list_x.append (line) file = open (Y, ' R ') for Line in file.readlines (): line = line.strip (' \ n ') &nBsp; list_y.append (line) list_x = set (list _x) list_y = set (list_y) diff_list = list (List_x.difference (list_y)) diff_str = ', '. Join (diff_list) print '%s:%s ' % (y,diff_str) file0 = ' standart ' file1 = ' node1.txt ' file2 = ' node2.txt ' file3 = ' Node3.txt ' diff (file0,file1) diff (file0,file2) diff (File0,file3)
This article is from the "Eight Miles" blog, so be sure to keep this source http://5921271.blog.51cto.com/5911271/1580104
Python comparison to file differences