I'm wondering which will be the best pythonic way to get all the same prefix for the values in a list.
- Rule #1: the word will be compound by the following parts: prefix + name + end (separated by '_'.
- Rule #2: all the word parts will be variable in length
- Rule #3: the end of the word is a two-character string starting with letter 'A' followed by a integer from 0-9 and could be the same for all the values in the list
- Rule #4: The names of each value will never be repeated in a list
- Rule #5: all the values in the list will have the same "unknown" prefix
Here are some examples from the rules listed above:
list1 = ['4_AR_P3_A0', '4_BCML_A0', '4_PA_RU_LR_A0', '4_Routes_A0']
get_prefix(list1) # output: '2'
list2 = ['MPL_TER_LA_Desse_A1', 'MPL_TER_LA_Magnit_Mach_A0', 'MPL_TER_LA_LR_A6', 'MPL_TER_LA_Routes_A0']
get_prefix(list2) # output: 'MPL_TER_LA'