title: How to properly split a specific string in Python
body: <p>I have a <strong>list</strong> of <strong>string</strong> values that represents the <code>id.age</code> of some users:</p>
  
  <pre><code>users = ["1.20", "2.35", "3", "4", "5.", "6.30", "7."]
  </code></pre>
  
  <p>How can I properly split it to get the <code>id</code> and <code>age</code> separately?</p>
  
  <p>Note that we have some data with the <code>age</code> information missing (e.g. <code>"3"</code> and <code>"4"</code>), and even worse, we have some data only with an <code>id</code> and a point (e.g. <code>"5."</code> and <code>"7."</code>).</p>
  
  <p>Sure I can use the split function, for example:</p>
  
  <pre><code>&gt;&gt;&gt; "1.2".split('.')
  ['1', '2']
  &gt;&gt;&gt; "2".split('.')
  ['2']
  &gt;&gt;&gt; "3.".split('.')
  ['3', '']
  </code></pre>
  
  <p>But, then I will need to check each result. Maybe, something like this:</p>
  
  <pre><code>res = "3.".split('.')
  id = int(res[0])
  if len(res) &gt; 1:
      if res[1] != "":
          age = int(res[1])
  </code></pre>
  
  <p>Another option is to use the <code>rpartition</code> function, for example:</p>
  
  <pre><code>&gt;&gt;&gt; "1.2".rpartition('.')
  ('1', '.', '2')
  &gt;&gt;&gt; "2".rpartition('.')
  ('', '', '2')
  &gt;&gt;&gt; "3.".rpartition('.')
  ('3', '.', '')
  </code></pre>
  
  <p>But I still need to check the results 'manually' and, in the second example, the value that should be the <code>id</code> is in the <code>age</code> position. (e.g. <code>('', '', '2')</code>).</p>
  
  <p>Is there a built in function that I can get the result like this?</p>
  
  <pre><code>&gt;&gt;&gt; "1.2".some_split_function('.')
  ('1', '.', '2')
  &gt;&gt;&gt; "2".some_split_function('.')
  ('2', None, None)
  &gt;&gt;&gt; "3.".some_split_function('.')
  ('3', '.', None)
  </code></pre>
  
  <p>So I can just call it in a loop like this:</p>
  
  <pre><code>for user_info in users:
      id, _, age = user_info.some_split_function('.')
      print int(id)
      if age is not None:
          print int(age)
  </code></pre>