title: Python: How do I take an imported text file with a list of names, two column format, and put them in python sorted alphabetically?
body: <p>This is what I have so far and its giving me errors when sort(), sorted() are used.
  I have to import the names and print them.
  Sort the names and print them again.</p>
  
  <p>The text file is formatted in two columns and is from notepad</p>
  
  <pre><code>Riggs, Jerry
  Stone, Ruby
  Wood, Holly
  Dover, Ilene
  Funt, Ella
  Storm, Wayne
  Lowe, Lyle
  Free, Bjorn
  Caine, Candy
  Carr, Rex
  Downs, Mark
  Twain, Lionel
  Thorn, Rose
  Shore, Rocky
  Bush, Rose
  Waters, Muddy
  Graves, Doug
  Stone, Roxanne
  Rivers, Wade
  Banks, Rob
  Carr, Rusty
  Trout, Brooke
  Carr, Rhoda
  Apple, Adam
  Ponds, Lily
  Burns, Forest
  Dover, Ben
  Sales, Clarence
  Nichol, Penny
  Beech, Sandy
  </code></pre>
  
  <p>I just can't get it to alphabetically sort the names or how to go about doing it. The desired outcome is that it will print the same style as the text file, in two columns. </p>
  
  <pre><code>def main():
      infile = open('names.txt','r')
      str = infile.read()
      print(str)
      name = str
  
      for name in str:
          ch = 'X'
          print(name)
  
      #for line in str:
          #str = line.readlines()
          #print(line)
  
      name = input('Who are you looking for? (case sensitive):') 
      if name in str:
          print(name,'was found in the list')
      else:
          print(name,'was not found in the list')
      infile.close()
  
  main()
  </code></pre>