Created
July 20, 2023 09:27
-
-
Save jackyliu16/9d5c15d90b930cf743892c06d207242e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment