#!/bin/env/python
import sys
import os
if len(sys.argv) == 3:
#We know the user typed Script then Filename
file = sys.argv.pop(2)
num = sys.argv.pop(1)
#Establish Vars
f1 = open(file)
counts = dict()
#Open the file and create a dictionary
for line in f1:
words = line.split()
for word in words:
if word not in counts:
counts[word] = 1
else:
counts[word] += 1
#print counts
#Iterate through all words and either establish word = 1 or increment
#counts = sorted(counts, key=words.get)
print counts
else:
print('Can you please use this format [script] [number] [file] ')
I need to have this program sort a file in a dictionary by words
I am having an issue, the sorting by the counts does not sort by the count number, I need this to sort to most frequent to least frequent does anyone see the issue. its outputting the numbers chopped off?