Splitting letters and numbers to figure out and assign value in table
Question: I currently have some code in Python where I have entered the values from a
table:

    
    
    rules = {   "213" : ( 0.00019, 3.5, 0.00019, 3.5 ),
            "222" : ( 0.00019, 4.0, 0.00019, min( 4.0, 4.1E-8 * dm**3 - 4.1E-5 * dm**2 + 0.017 * dm + 1.35 ) ),
            "223" : ( 0.0003,  4.5, 0.0003,  4.5 ),
            "230" : ( 0.00017, 4.5, 0.00017, 3.3 ),
            "231" : ( 0.00027, 5.5, 0.00027, 5.1E-6 * dm**2 - 0.0057 * dm + 4.6 ),
            "232" : ( 0.00036, 6.0, 0.00036, 7.1E-6 * dm**2 - 0.007 * dm + 5.79 ),
            "239" : ( 0.00017, 4.5, 0.00017, 2.9 ),
            "240" : ( 0.00027, 6.5, 0.00027, 9.1E-6 * dm**2 - 0.01 * dm + 6.9 ),
            "241" : ( 0.00049, 7.0, 0.00049, 3.1E-5 * dm**2 - 0.032 * dm + 8.7 ) }
    serialNumber = [ "name" ][ 0 : 3 ]
    try:
        return rules[ serialNumber ]
    

The columns (readings from L-R in the brackets): F1ISO, F0ISO, F1COR, F0COR

What I would like to do, with an input 'name' (the name being a combination of
numbers and letters and always in the form: 11111A for example, there can be
two letters at the end).

I want to be able to split the 'name' into the letters and numbers but more
importantly I am looking at the first 3 numbers and the letters. With these
first three numbers I want to be able to read from the 'table' above but the
values which are chosen also depend on the letter.

The main rules are: If the letter is equal to V then the 'ISO' values are
taken. Any other combination takes the 'COR' values.

Thank you to anyone who can help.


Answer: This could be helpful to understand how to get the two parts from your entry

    
    
    >>> name =  "11111A"
    >>> ser = name[:3]     # first 3 characters
    >>> code = name[3:]    # rest of chars after the third
    >>> ser
    '111'
    >>> code
    '11A'
    >>>
    

or maybe:

    
    
      >>> code = name[-1]     # last character
      >>> code
      'A'
    

then, in the same way:

    
    
    >>> contents = rules[ser]
    >>> if code == 'V':
    ...     print contents[:2]
    ... else:
    ...     print contents[2:]
    

