I'm trying to do something like:
a = input("Enter the name of your list")
"{n}".format(n = a) = []
Which is obviously doesn't work. Is there any way to do this?
I'm trying to do something like:
a = input("Enter the name of your list")
"{n}".format(n = a) = []
Which is obviously doesn't work. Is there any way to do this?
One way to have a variable with a user-supplied name is to create that variable as an item within a dictionary.
the_dict = {}
a = input("Enter the name of your list")
the_dict[a] = []
Use exec
and eval
:
a = input("Enter the name of your list")
exec(str(a)+"=[]")
print(eval(a))
This does exactly what you want, while this is not recommended, for better solution please refer to John's answer.