-4

I am trying to remove user input from the list I have made but can't get it to work.

New to programming in general :|

text = ["Menu1_test", "Menu2_test", "Menu3_test", "Menu4_test", "Menu 5_test"]

text_remove = input("What do you want removed?")


def text_remover(text, text_remove):

     i = 0         
     for w in text:
        text.remove(text_remove[i])
        i=i+1
        print(w+" removed")

text_remover(text, text_remove)
print (text)
Mazdak
  • 105,000
  • 18
  • 159
  • 188
  • `text_remove` is not an array you can't call it on i'th position like`text_remove[i]`, input gives you just a single string. – Klaus Jul 23 '15 at 12:58
  • Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – Morgan Thrapp Jul 23 '15 at 12:59
  • @KlausPrinoth: There are various errors in the OP code, but in isolation `text_remove[i]` is a valid construction. `text_remove` is a string and `text_remove[i]` is the `i`th character of that string. – PM 2Ring Jul 23 '15 at 13:07
  • @PM2Ring oh i didn't know that this works, but why does then exist the function `list()` that makes a char array out of a string: http://stackoverflow.com/a/4978792/4999641 – Klaus Jul 23 '15 at 13:34
  • 1
    @KlausPrinoth: Python has various types of built-in sequence objects with different properties for different purposes. a `str` is an immutable sequence object of chars, so you can't change the chars in it. A `list` is a general-purpose sequence object so it can contain anything, and it's mutable, so you _can_ change its contents. A `tuple` is also general-purpose but like a `str` it's immutable. – PM 2Ring Jul 23 '15 at 13:40
  • @PM2Ring OK, thanks for the clarification! – Klaus Jul 23 '15 at 13:41
  • Does this answer your question? [Difference between del, remove and pop on lists](https://stackoverflow.com/questions/11520492/difference-between-del-remove-and-pop-on-lists) – Georgy Jun 21 '20 at 14:05

1 Answers1

1

try this https://docs.python.org/2/tutorial/datastructures.html#more-on-lists

read the functions available for lists and try them out,

text = ["Menu1_test", "Menu2_test", "Menu3_test", "Menu4_test", "Menu 5_test"]

text_remove = input("What do you want removed?")

def text_remover(text, text_remove):

    text.remove(text_remove)

text_remover(text, text_remove)
print (text)
Ja8zyjits
  • 1,433
  • 16
  • 31