fork download
  1. def sort_by_length(words):
  2. t = []
  3. for word in words:
  4. t.append((len(word), word))
  5. t.sort(reverse=True)
  6.  
  7. res = []
  8. for length, word in t:
  9. res.append(word)
  10. return res
  11.  
  12. w = ["abcd", "za", "wyya", "dssffgdg"]
  13.  
  14. print sort_by_length(w);
Success #stdin #stdout 0.01s 7896KB
stdin
Standard input is empty
stdout
['dssffgdg', 'wyya', 'abcd', 'za']