I'm having a lot of trouble with the following task for one of my assignments in python. Basically I need to take the user input and replace any words in the input and replace them with words from a list if they are in it. Here's an example
list_of_words = \
[
[['Hi', "G'day", 'Hey'], 'Hello'],
[['Bye', 'Farewell', 'Later', 'Ciao', 'Quit'], 'Goodbye'],
[['Nope', 'Nah'], 'No']
]
So if the user types 'Hi, how are you', they should get in return 'Hello how are you'
The example list that I need to work with is the same layout, but much larger, so I didn't think it would be necessary to post it all here.
I think I know how to approach this, but keep messing up. I tried to use a for loop to say for words that the user types, if they are in the list_of_words, replace them with the line they are on and the second part of the list. I have split up the users input into a list, so the loop should just iterate through each item in that list I'd imagine. We've been told to not use .replace() by the way.
I've tried to use a counter to make the loop go to a different line in the list each time, but don't think that's the way to go. I think I need to do a loop inside a loop, but I get confused. Any pointers to show me in the right direction would be appreciated.
list_of_words = \
[
[['Hi', "G'day", 'Hey'], 'Hello'],
[['Bye', 'Farewell', 'Later', 'Ciao', 'Quit'], 'Goodbye'],
[['Nope', 'Nah'], 'No']
]
So if the user types 'Hi, how are you', they should get in return 'Hello how are you'
The example list that I need to work with is the same layout, but much larger, so I didn't think it would be necessary to post it all here.
I think I know how to approach this, but keep messing up. I tried to use a for loop to say for words that the user types, if they are in the list_of_words, replace them with the line they are on and the second part of the list. I have split up the users input into a list, so the loop should just iterate through each item in that list I'd imagine. We've been told to not use .replace() by the way.
I've tried to use a counter to make the loop go to a different line in the list each time, but don't think that's the way to go. I think I need to do a loop inside a loop, but I get confused. Any pointers to show me in the right direction would be appreciated.
Comment