""" This file takes the column closest to the right and performs a set analysis on it """ from typing import List, Set def getRightCol(lines: List[str]) -> List[str]: """ get the rightest column of a kind of tables lines: the data like [ "0.01 0.000 2 18 9 access " "0.00 0.000025 1 25 22 readlink " "0.00 0.000019 0 96 mmap " "0.00 0.000017 1 12 stat " ] return: the item in rightest columns [ "access", "readlink", "mmap", "stat" ] """ return [line.split()[-1] for line in lines] def get_intersection(list_a: List[str], list_b: List[str]) -> Set[str]: """ get the item both in a and b """ return set(list_a) & set(list_b) def get_difference(list_a: List[str], list_b: List[str]) -> Set[str]: """ get the item which existed in a but not b """ return set(list_a) - set(list_b) if __name__ == "__main__": subscriber = None publisher = None with open("p_out", "r") as File: publisher = File.readlines() with open("s_out", "r") as File: subscriber = File.readlines() assert(publisher != None and subscriber != None) pub_list = getRightCol(publisher) sub_list = getRightCol(subscriber) intersection = get_intersection(pub_list, sub_list) print(intersection) diff = get_difference(pub_list, sub_list) print(diff) diff = get_difference(sub_list, pub_list) print(diff)