So my script uses two dictionaries (see output): First dictionary contains the article ID's and an empty 0 rank and is my input dictionary that needs to be adjusted. The second dictionary contains the article ID's plus their rankings and functions as my ranking reference index.
Code:
#get input IDs from text file and convert to dict:
with open("article_ID.txt") as f:
content = {x for x in f.read().split()}
ids = dict.fromkeys(content, '0')
print (ids)
# Generate ranking dict from csv file:
rankings = dict()
f = open("ranking_sheet.csv")
for line in f:
line = line.strip('\n')
(key, val) = line.split(",")
rankings[key] = val
print(rankings)
Output:
{'86': '0', '126': '0', '58': '0', '369': '0', '172': '0', '329': '0', '271': '0', '97': '0'}
{'329': '1', '271': '2', '172': '3', '58': '4', '97': '5', '369': '6', '126': '7', '86': '8'}
Desired Output is that the ids dictionary is reordered based on the actual ranking system from the rank dict, starting from the highest ranked ID. So the 0 gets changed to the corresponding rank.