Python List Removal and Number Subtracter | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python List Removal and Number Subtracter

I have two questions that I cannot seem to find answers about on the internet: 1) How do you limit the number of inputs someone can give? What I mean is if you type in a wrong input a certain number of times, the program will give them a message such as "You Failed." 2) How do you remove a word from a list after it has been used so it cannot be repeated for the future?

24th Sep 2019, 4:30 PM
Code Babylon
Code Babylon - avatar
7 Answers
+ 2
1) That problem is only in online compilers, such as SoloLearn playground is. I'd recommend to download an IDE that can run Python code. When Python is intepreted in your device the input works smarter. 2) You can remove an item from a list using 2 different methods: With index: <list>.pop(<index>) With value: <list>.remove(<value>)
24th Sep 2019, 4:44 PM
Seb TheS
Seb TheS - avatar
+ 1
#Maybe pop method would still solve the second problem? #Iterating from last index to first, because list size changes. for i in range(len(<list>)-1, -1, -1): print(<list>.pop(i)) #Now the list would have been empty.
24th Sep 2019, 5:08 PM
Seb TheS
Seb TheS - avatar
+ 1
No
24th Sep 2019, 5:12 PM
Seb TheS
Seb TheS - avatar
+ 1
But I did not see anything wrong in these clips. But if you want to remove an item after using it, you can either use pop method or do it manually or you can self define a function to do it automatically.
24th Sep 2019, 5:17 PM
Seb TheS
Seb TheS - avatar
0
Seb TheS 1) I use VS Code for my coding (not a fan of Playground.) 2) Is that for removing the value that was just used? Not one that is just standing by?
24th Sep 2019, 5:00 PM
Code Babylon
Code Babylon - avatar
0
Were you testing all of those, Seb TheS?
24th Sep 2019, 5:11 PM
Code Babylon
Code Babylon - avatar
0
Seb TheS I'll test it for myself and let you know the results. Thanks
24th Sep 2019, 5:18 PM
Code Babylon
Code Babylon - avatar