Created
October 26, 2014 09:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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