title: Sorting content of a .txt file in Python 3 line by line
body: <p>I want to sort content of a .txt file that is read into Python from its highest to lowest numeric value.</p>
  
  <p><img src="https://i.stack.imgur.com/tZDW6.jpg" alt="enter image description here"></p>
  
  <p>Using the following code:</p>
  
  <pre><code>with open("externalFile.txt", "r") as file:
      content = file.read()
      print(content)
  
  list = content.splitlines()
  
  def f(text):
      return int(text) if text.isdigit() else text
  
  def f1(text):
      return [ func(z) for z in re.split('(\d+)', text) ]
  
  list.sort(key=f1)
  </code></pre>
  
  <p>creates a list and within that list it sorts the content both alphabetically and numerically, as shown below.</p>
  
  <p><img src="https://i.stack.imgur.com/D2ISg.jpg" alt="enter image description here"></p>
  
  <p>However, I only want the content to be sorted numerically in Python, please see below.</p>
  
  <p><img src="https://i.stack.imgur.com/YFo9D.jpg" alt="enter image description here"></p>