# We take a file, open it, split into words
# Then create a dictionary using word as the key and the count as the value
file_name = input('Enter the path and the name of the file: ')
fhand = open(file_name)
counts = {}
for line in fhand:
words = line.split()
for word in words:
counts[word] = counts.get(word, 0) + 1
lst = []
# We get a list of tuples, tuples contain value first and key second
# Then we sort that list in descending order
lst = sorted([(v,k) for k,v in counts.items()], reverse= True)
print(lst) # You can eliminate this line if you want
# We print the first ten key and value of the list
# Consider that we have changed the order from value, key to key and value here
print([(v,k) for k,v in lst[:10]])
# We close the file which we have opened
fhand.close()