r/PythonLearning • u/SpaghettiCoded • Jul 19 '25
Appending a list
Good morning yall! So im trying out one of the suggestions from a previous post where I allow the program to "learn" new words (adjusting the suggestion a little). Where I am running into problems is I tried using the .add method with {} and it did work, but it didnt quite add the user_response to the positive_response list quite like I hoped so i tried appending a list and it sort of did the same thing.
Long story short: Is there a way to have the response appended, have the script run a new appended list, then finally use .insert(-1) to insert the new response into the first list? or even better is there an easy way to actually add the new word to the list?
47
Upvotes
1
u/cancerbero23 Jul 19 '25
Hi!
Actually,
appendmethod should do the work,addmethod is for sets, which work good here too, though.insertmethod inserts an element BEFORE the requested index, soinsert(-1)would insert the element in the last but one position.Aside from that, I see some problems in your code:
The method
check_day_statusis receiving an argument calledday, which is never used. Instead a non-defined variable calleduser_responseis used.For confirmation you're asking for a "Y" or a "N", but lower-cases "y" or "n" are being checked. You should change your
ifstatements forconfirmation == "y" or confirmation == "Y", or even betterconfirmation.lower() == "y"(same for "n").Plus, you aren't considering cases when user neither enters "y" nor "n". You should consider an
elsecase, something like:Good luck!