title: Python - read everything after second or third last dot
body: <p>I need to get the below output from the input.</p>
  
  <pre><code>Input1: firstname.middlename.lastname.city.state
  Expected output: city.state
  
  Input2: firstname.middlename.lastname.city.state.
  Expected output: city.state
  </code></pre>
  
  <p>This is the expression i have that works when the Input does not have . at the end:</p>
  
  <pre><code>'firstname.middlename.lastname.city.state'['firstname.middlename.lastname.city.state'[:'firstname.middlename.lastname.city.state'.rfind(".")].rfind(".")+1:]
  </code></pre>
  
  <p>How do i modify this expression so that <code>Input2</code> has the same output as <code>Input1</code></p>