Skip to content

Instantly share code, notes, and snippets.

@mh-github
Created October 26, 2014 09:08
Show Gist options
  • Select an option

  • Save mh-github/fec41cbb8dce234f231f to your computer and use it in GitHub Desktop.

Select an option

Save mh-github/fec41cbb8dce234f231f to your computer and use it in GitHub Desktop.
sorting words with Python (from pythonlearn.com - http://www.pythonlearn.com/html-008/cfbook011.html
#! /usr/bin/env python
txt = 'but soft what light in yonder window breaks'
words = txt.split()
t = list()
for word in words:
t.append((len(word), word))
t.sort(reverse = True)
res = list()
for length, word in t:
res.append(word)
print res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment