title: How do I sort a text file after the last instance of a character?
body: <p>Goal: Sort the text file alphabetically based on the characters that appear AFTER the final slash. Note that there are random numbers right before the final slash.</p>
  <p>Contents of the text file:</p>
  <pre><code>https://www.website.com/1939332/delta.html
  https://www.website.com/2237243/alpha.html
  https://www.website.com/1242174/zeta.html
  https://www.website.com/1839352/charlie.html
  </code></pre>
  <p>Desired output:</p>
  <pre><code>https://www.website.com/2237243/alpha.html
  https://www.website.com/1839352/charlie.html
  https://www.website.com/1939332/delta.html
  https://www.website.com/1242174/zeta.html
  </code></pre>
  <p>Code Attempt:</p>
  <pre><code>i = 0
  for line in open(&quot;test.txt&quot;).readlines(): #reading text file
      List = line.rsplit('/', 1)            #splits by final slash and gives me 4 lists
      dct = {list[i]:list[i+1]}             #tried to use a dictionary 
      sorted_dict=sorted(dct.items())       #sort the dictionary
  
  textfile = open(&quot;test.txt&quot;, &quot;w&quot;)
  for element in sorted_dict:
      textfile.write(element + &quot;\n&quot;)
  textfile.close()
     
  </code></pre>
  <p>Code does not work.</p>