title: Python sorting html table
body: <p>I am looping through a list of servers and connecting with OpenSSL, to retrieve the  SSL cert, and grabbing the server name, the date the cert expires, and calculating the number of days until cert expires. I am then building an html table with the data. The columns are Host, Hostname, Expiration Date, and Remaining Days. What is the best way to sort the table by the "Remaining Days" column? </p>
  
  <pre><code># Update the hosts entry
      ssl_results[str(ip)][0] = host
      ssl_results[str(ip)][1] = server_name
      ssl_results[str(ip)][2] = exp_date
      ssl_results[str(ip)][3] = days_to_expire
  
      # Loop through the ssl_results entries and generate a email + results file
      try:
  
          # variable to hold html for email
          SSLCertificates = """&lt;html&gt;
                              &lt;head&gt;
                                &lt;style&gt;
                                      table{width: 1024px;}
  
                                      table, th, td {
                                          border: 1px solid black;
                                          border-collapse: collapse;
                                      }
  
                                      th, td {
                                          padding: 5px;
                                          text-align: left;
                                      }
  
                                      ul:before{
                                        content:attr(data-header);
                                        font-size:120%;
                                        font-weight:bold;
                                        margin-left:-15px;
                                      }
                                  &lt;/style&gt;
                                &lt;/head&gt;
                              &lt;body&gt;
                                &lt;p&gt;&lt;h2&gt;Blah, &lt;/h2&gt;
                                &lt;h3&gt;SSL Expiration Summary:&lt;/h3&gt;
                                &lt;span style="color:red;"&gt;&lt;b&gt;Blah Blah Blah.&lt;b&gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;
                                &lt;table id=\"exp_ssls\"&gt;&lt;tr&gt;&lt;th&gt;Host&lt;/th&gt;&lt;th&gt;Hostname&lt;/th&gt;&lt;th&gt;Expiration Date&lt;/th&gt;&lt;th&gt;Remaining Days&lt;/th&gt;&lt;/tr&gt;
                            """
  
          for entries in ssl_results:
              SSLCertificates += "&lt;tr&gt;&lt;td&gt;" + str(entries) + "&lt;/td&gt;&lt;td&gt;" + str(ssl_results[entries][1]) + "&lt;/td&gt;&lt;td&gt;" + str(
                  ssl_results[entries][2]) + "&lt;/td&gt;&lt;td&gt;" + str(ssl_results[entries][3]) + "&lt;/td&gt;&lt;/tr&gt;"
  
          SSLCertificates += """&lt;/body&gt;
                      &lt;/html&gt;"""
  
          f = open('SSLCertificates.html', 'w')
          f.write(SSLCertificates)
          f.close()
          filename = 'SSLCertificates.html'
          attachment = open(filename, 'rb')
  </code></pre>