title: Python Switch/Case Statement Adaptation
body: <p>Ok, at the risk of being ridiculed for not 'trying harder', I have a scenario that I've been attempting to adapt to a pythonic switch case statement.  I know python has the new <code>match</code> method in 3.10 but I'm limited to 3.8.10 in my AWS use case.  I've been reading up on switch cases in other languages and I want to find a pythonic way to convert the following jumbled mess of <code>if/elif/else</code> statements to a clean switch case.  I am wondering what others would do in this scenario</p>
  <p>OBJECTIVE:  I have a filename that will be passed into this sequence of code and I need to return the first three items (i.e. <code>transaction_recipient_verification</code>, <code>transaction_account_tokenization</code>, etc).  Occasionally the code will receive a filename containing &quot;field_results&quot; or &quot;issuers&quot; and I need to make sure that the trimmed return string contains the respective case.</p>
  <pre class="lang-rb prettyprint-override"><code>import random
  
  sampleKeys = [
      'transaction_recipient_notification_status_sent/transaction_recipient_notification_status_sent_2021_10_29_12_02_14.snappy',
      'transaction_recipient_payment_status_success/transaction_recipient_payment_status_success_2021_10_29_12_02_14.snappy',
      'transaction_recipient_verification_rvdm_failure/transaction_recipient_verification_rvdm_failure_2021_10_29_12_02_14.snappy',
      'transaction_recipient_verification_rvdm_failure_field_results/transaction_recipient_verification_rvdm_failure_2021_10_29_12_02_14.snappy',
      'transaction_recipient_authentication_status_success/transaction_recipient_authentication_status_success_2021_10_29_12_02_14.snappy',
      'transaction_recipient_authentication_status_success_field_results/transaction_recipient_authentication_status_success_2021_10_29_12_02_14.snappy',
      'transaction_account_tokenization_success/transaction_account_tokenization_success_2021_10_29_12_02_14.snappy',
      'transaction_account_tokenization_success_issuers/transaction_account_tokenization_success_2021_10_29_12_02_14.snappy',
      'transaction_recipient_payment_status_terminated/transaction_recipient_payment_status_terminated_2021_10_29_12_02_14.snappy',
      'transaction_recipient_verification_rvdm_success/transaction_recipient_verification_rvdm_success_2021_10_29_12_02_14.snappy',
      'transaction_recipient_verification_rvdm_success_field_results/transaction_recipient_verification_rvdm_success_2021_10_29_12_02_14.snappy',
      'transaction_recipient_notification_status_received/transaction_recipient_notification_status_received_2021_10_29_12_02_14.snappy',
      'transaction_recipient_authentication_status_success/transaction_recipient_authentication_status_success_2021_10_29_11_17_45.snappy'
      
  ]
  
  key = random.choice(sampleKeys)
  
  array_data = any(substring in key for substring in ['_issuers', '_field_results'])
  if not array_data:
      if 'transaction_recipient_notification' in key:
          keySubject = 'transaction_recipient_notification'
      elif 'transaction_recipient_authentication' in key:
          keySubject = 'transaction_recipient_authentication'
      elif 'transaction_recipient_verification' in key:
          keySubject = 'transaction_recipient_verification'
      elif 'transaction_account_verification' in key:
          keySubject = 'transaction_account_verification'
      elif 'transaction_account_tokenization' in key:
          keySubject = 'transaction_account_tokenization'
      elif 'transaction_recipient_payment' in key:
          keySubject = 'transaction_recipient_payment'
  else:
      if '_issuers' in key:
          if 'transaction_recipient_notification' in key:
              keySubject = 'transaction_recipient_notification_issuers'
          elif 'transaction_recipient_authentication' in key:
              keySubject = 'transaction_recipient_authentication_issuers'
          elif 'transaction_recipient_verification' in key:
              keySubject = 'transaction_recipient_verification_issuers'
          elif 'transaction_account_verification' in key:
              keySubject = 'transaction_account_verification_issuers'
          elif 'transaction_account_tokenization' in key:
              keySubject = 'transaction_account_tokenization_issuers'
          elif 'transaction_recipient_payment' in key:
              keySubject = 'transaction_recipient_payment_issuers'
      elif '_field_results' in key:
          if 'transaction_recipient_notification' in key:
              keySubject = 'transaction_recipient_notification_field_results'
          elif 'transaction_recipient_authentication' in key:
              keySubject = 'transaction_recipient_authentication_field_results'
          elif 'transaction_recipient_verification' in key:
              keySubject = 'transaction_recipient_verification_field_results'
          elif 'transaction_account_verification' in key:
              keySubject = 'transaction_account_verification_field_results'
          elif 'transaction_account_tokenization' in key:
              keySubject = 'transaction_account_tokenization_field_results'
          elif 'transaction_recipient_payment' in key:
              keySubject = 'transaction_recipient_payment_field_results'
  print(f'BEFORE ===&gt; {key}')
  print(f'AFTER  ===&gt; {keySubject}')
  </code></pre>
  <h2>Possible Direction:</h2>
  <pre class="lang-rb prettyprint-override"><code>import re
      
  class MainKeyHandleSwitch:
      
      ARRAY_OPTIONS = ['_issuers', '_field_results']
          
      def __init__(self,key):
          self._original_key = key
          self._array_data = any(substring in key for substring in self.ARRAY_OPTIONS)
          self._trimmed_dict = self.trimmed_dict()
      
      @property
      def get_trimmed_dict(self):
          return self._trimmed_dict
      
      @property
      def get_trimmed_key(self):
          return self.__get_key_subject__()
      
      def trimmed_dict(self):
          trim_dict = dict()
          trim_dict['case_one'] = re.search('transaction_recipient_notification+', self._original_key)
          trim_dict['case_two'] = re.search('transaction_recipient_authentication+', self._original_key)
          trim_dict['case_three'] = re.search('transaction_recipient_verification+', self._original_key)
          trim_dict['case_four'] = re.search('transaction_account_verification+', self._original_key)
          trim_dict['case_five'] = re.search('transaction_account_tokenization+', self._original_key)
          trim_dict['case_six'] = re.search('transaction_recipient_payment+', self._original_key)
          return trim_dict
      
      def __get_key_subject__(self):
          obj = next(item for item in list(self._trimmed_dict.values()) if item is not None)
          if not self._array_data:
              return obj.group(0)
          else:
              if '_issuers' in self._original_key:
                  return f'{obj.group(0)}_issuers'
              
              elif '_field_results' in self._original_key:
                  return f'{obj.group(0)}_field_results'        
  </code></pre>
  <p><strong>And the code to test the class:</strong></p>
  <pre class="lang-rb prettyprint-override"><code>import random
  
  key = random.choice(sampleKeys)
  print(f'before ===&gt; {key}')
  a = MainKeyHandleSwitch(key)
  trimmed_key = a.get_trimmed_key
  print(f'after  ===&gt; {trimmed_key}')
  </code></pre>