Skip to content

Instantly share code, notes, and snippets.

@mchirico
Created March 1, 2013 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mchirico/5068798 to your computer and use it in GitHub Desktop.
Save mchirico/5068798 to your computer and use it in GitHub Desktop.
Back of the envelope sorts using dictionary keys or sorts of values
def num(m):
h={}
for i in m:
j=i.split(",")
if (j[0] in h):
h[j[0]]=h[j[0]]+1
else:
h[j[0]]=1
return h
# sortAndWrite(n)
def sortAndWrite(n):
sort=sorted(n, key=lambda key: n[key])
f=open('sorted.value','w')
for i in sort:
f.write(str(i)+","+str(n[i])+"\n")
f.close()
f=open('sorted.key','w')
for i in sorted(n.iterkeys()):
f.write(str(i)+","+str(n[i])+"\n")
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment