Okay, so I am having a problem swapping part of a string with part of another string in a list. I've seen the other similar questions on this site but none of them seem to work for me.
Let's say I have a list:
sentList = ['i like math', 'i am a cs expert']
Now I want to switch 'math' with 'cs' using variables determined by user input.
currentWord = input('Swap word: ')
newWord = input('with word: ')
So, now how would I swap the two so that my list would return the following:
sentList = ['i like cs', 'i am a math expert']
As always, thank you for any help. I think I can use the replace function but am not sure how. I imagine it would look something like this:
sentList = [sentListN.replace(currentWord, newWord) for sentListN in sentList]
But, obviously that does not work.