Home
NOTE: I'm in the middle of upgrading the site. Most things are in place, but some things are missing and/or broken. This includes alt text for images. Please bear with me while I get things fixed.

Sort A String Of Lines In Python

This is how to sort a string with lines of text in python

string = '''
  d
  a
  c
  
  b
  e
  '''

  lines = sorted(
      list(
          filter(lambda x: x != '', string.split("\n"))
      ))

  print(lines)

#+RESULTS : : ['a', 'b', 'c', 'd', 'e']

The [TODO: Code shorthand span ] removes empty lines

~ fin ~