Skip to main content
1 of 2
Winston Ewert
  • 30.4k
  • 4
  • 51
  • 79
data = ["something", "something else", "blah", "a string"]
result = [(x, len(x)) for x in sorted(data, key = len)]

Basically, its more straightforward to sort first then decorate. Although, I'm not sure why you would need the length of the list in your tuple. If you don't really need it sorting by length can be much shorter.

Winston Ewert
  • 30.4k
  • 4
  • 51
  • 79