Untitled

 avatar
unknown
plain_text
2 years ago
754 B
3
Indexable
file_path_2020 = './revenue2020.txt'
file_path_2021 = './revenue2021.txt'

import pprint

def dictavtxt(filnavn):
    f = open(filnavn + ".txt", "r")
    str1 = f.readlines()
    dict1 = {}
    for x in range(len(str1)):
        split1 = str1[x].split(",")
        key1 = split1[0]
        value1 = split1[1].strip("\n")
        dict1[key1] = int(value1)
    f.close()
    return dict1

pprint.pp(dictavtxt("revenue2020"))
print("\n")
pprint.pp(dictavtxt("revenue2021"))

def top5(h):
    sorted_h = sorted(h.items(), key=lambda kv: kv[1])
    for x in range(0, len(sorted_h)-5):
        sorted_h.remove(sorted_h[x])
    pprint.pp(sorted_h)
    print("\n")
    
top5(dictavtxt("revenue2020"))

top5(dictavtxt("revenue2021"))
Editor is loading...