User:Mths/rwrm writing machines
script
import re, operator, sys
fn = sys.argv[1]
with open(fn, "r") as f:
text = f.read()
words = re.findall(r'\w+', text)
d = {}
for j in words:
d[j] = d.get(j,0) + 1
sorted_d = sorted(d.iteritems(), key=operator.itemgetter(1))
newwords = []
templist = []
for string, i in sorted_d:
while i > 0:
templist.append(string)
i -= 1
newwords = templist
#templist = []
str1 = ' '.join(newwords)
print str1