I have two files, "ranked.txt" and "sorted.txt". Sorted.txt is a smaller subset from ranked.txt that is sorted in alpha order. However ranked.txt preserves the ranking of words I would like to keep.
How do I check the rank of every word in sorted.txt when matched to the original ranked.txt? I want to output the rank (which is the line number) from ranked.txt into sorted.txt.
ranked.txt:
1 the
2 quick
3 brown
4 fox
5 jumped
sorted:
brown
fox
jumped
quick
the
output.txt:
3 brown
4 fox
5 jumped
2 quick
1 the
This is what I have so far:
for word in sorted_list:
for num, line in enumerate(ranked_list, 1):
if word in line:
print word, '\t', num
But this doesn't do exactly what I want... anyone help?