I am trying to do the following:
- create an array of random data
- create an array of predefined codes (AW, SS)
- subtract all numbers as well as any instance of predefined code.
- if a string called "HL" remains after step 3, remove that as well and take the next alphabet pair. If a string called "HL" is the ONLY string in the array then take that.
I do not know how to go about completing steps 3 - 4.
1.
array_data = ['HL22','PG1234-332HL','1334-SF-21HL','HL43--222PG','HL222AW11144RH','HLSSDD','SSDD']
2.
predefined_code = ['AW','SS']
3.
ideally, results for this step will look like
result_data = [['HL'],['PG,HL'],['SF','HL'],['HL','PG'],['HL','RH'],
['HL','DD'],['DD']
4. ideally, results for this step will look like this:
result_data = [['HL'],['PG'],['SF'],['PG'],['RH'], ['DD'],['DD']
for step 3, I have tried the following code
not_in_predefined = [item for item in array_data if item not in predefined_code]
but this doesnt produce the result im looking for, because it it checking item against item. not a partial string match.