Created
November 10, 2022 19:18
-
-
Save Abuton/769355a961250ab650d077a0338faa93 to your computer and use it in GitHub Desktop.
This file contains 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
import re | |
with open("company (2).txt") as file: | |
com = file.read() | |
com_split = com.split("-------") | |
com_list = com_split[3].replace('--', '').split("\n")[1:-3] | |
a = [x.split('(') for x in com_list] | |
dict_prod = {} | |
for i in a: | |
dict_prod[i[0]] = i[1].replace(')', '') | |
for i in dict_prod.keys(): | |
if 'million' in dict_prod[i]: | |
dict_prod[i] = float(re.findall(r'\d+\.\d+|\d+', dict_prod[i])[0]) * 1000000 | |
elif 'thousand' in dict_prod[i]: | |
dict_prod[i] = float(re.findall(r'\d+\.\d+|\d+', dict_prod[i])[0]) * 1000 | |
sorted_dict = {k: v for k, v in sorted(dict_prod.items(), key=lambda item: item[1], reverse=True)} | |
for count, product in enumerate(sorted_dict): | |
count += 1 | |
if count <= 5: | |
print(f"{count}. {product}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment