title: How to optimize my aggregation code ? (Python)
body: <p>In order to continue to learn and progress, I am wondering about this code :</p>
  <pre><code>def replace_titles(x) :
      title = x['Title']
      if title in ['Dr'] : # Dr to Mr or Mrs
          return 'Mr' if x['Sex'] == 'male' else 'Mrs'
      elif title in ['Don', 'Sir', 'Capt', 'Col', 'Major', 'Rev', 'Jonkheer', 'Mr'] : # Male titles to Mr or Children
          return 'Children' if x['Age'] &lt; 14.5 else 'Mr'
      elif title in ['Master'] : # Master to Children
          return 'Children'
      elif title in ['Lady', 'Countess', 'Dona', 'Mme', 'Miss', 'Mlle', 'Ms', 'Mrs'] : # Female titles to Children or Mrs
          return 'Children' if x['Age'] &lt; 14.5 else 'Mrs'
      else :
          return title
  </code></pre>
  <p>I want to aggregate titles into more meaningful categories and list all the children &lt; 14.5 years.</p>
  <p>How do you think I can optimize this code ? <em>(shorter and more efficient)</em></p>
  <p>Maybe with match-case in Python 3.10.x ?</p>
  <p>Thank you</p>