I have the following string:
'recipe : cake, cookies, pizza'
How would I remove the punctuation and the string "recipe" so that I would get the following output?
['cake', 'cookies', 'pizza']
The colon can be any type of punctuation.
So I tried multiple things that did not work, one using a for loop to iterate over string.punctuation and check if the punctuation was in the string after splitting it but it doesn't work. Please point me to the right direction. This is sort of what I was going for:
import string
string = 'recipe : cake, cookies, pizza'
for punctuation in string.punctuation:
if punc in string:
*Then split by that punctuation and by ',' while also removing whitespace. Pls help
Aucun commentaire:
Enregistrer un commentaire