0

I am making a program right now in python. To make the program efficient I was hoping there is a way to take user input and change it into the name of a list. Basically, like removing the quotes on it.

Like this input = input("What is your name") Let's say your name is Ted. I have a list that is Ted = ["Blah, Blahh] So basically I want to convert the input which would be "Ted", to just be Ted.

John Kugelman
  • 330,190
  • 66
  • 504
  • 555

3 Answers3

3

You can try a dictionary instead:

dict_1 = {}
name = input("What is your name")
dict_1[name] = ["blah", "blah"]

Read more about dictionaries on Internet. You shouldn't use input as the name of a variable since it is a Python reserved keyword.

Christian Tapia
  • 32,670
  • 6
  • 50
  • 72
0
lists = {
    "Ted": ["Blah", "Blahh"],
    "Joe": ["Foob", "zerx"],
}
name = input("What is your name? ")
if name not in lists:
    print("Don't have a list for that name")
else:
    print("The list is %s" % (lists[name],))

Use raw_input instead of input if you're using Python 2.x.

Claudiu
  • 216,039
  • 159
  • 467
  • 667
0

I believe this is want you want:

globals()['ted'] = 42
print(ted)
uvdn7
  • 83
  • 4