Jul-11-2022, 08:02 AM
Hello,
I have to split a string using a variable found in a list, but it doesn't work. This is my code:
causali = ['IP', 'TP', 'PR1', 'PR2', 'PR3', 'TP', 'BC', 'BF', 'VP', 'RP']
file = ('12011191-92-95-202-203_220701_PR1 - Copia')
print (file)
causale=str([ele for ele in causali if ele in file])
print (causale)
ls=file.split(causale)
print (ls)
and this is my output:
12011191-92-95-202-203_220701_PR1 - Copia
['PR1']
['12011191-92-95-202-203_220701_PR1 - Copia']
What's wrong?
I have to split a string using a variable found in a list, but it doesn't work. This is my code:
causali = ['IP', 'TP', 'PR1', 'PR2', 'PR3', 'TP', 'BC', 'BF', 'VP', 'RP']
file = ('12011191-92-95-202-203_220701_PR1 - Copia')
print (file)
causale=str([ele for ele in causali if ele in file])
print (causale)
ls=file.split(causale)
print (ls)
and this is my output:
12011191-92-95-202-203_220701_PR1 - Copia
['PR1']
['12011191-92-95-202-203_220701_PR1 - Copia']
What's wrong?