Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将用户输入更改为列表的名称_Python_List_Input - Fatal编程技术网

Python 将用户输入更改为列表的名称

Python 将用户输入更改为列表的名称,python,list,input,Python,List,Input,我正在用python编写一个程序。为了提高程序的效率,我希望有一种方法可以接受用户输入并将其更改为列表的名称。基本上,就像去掉上面的引号 像这样input=input(“你叫什么名字”) 假设你的名字是特德。 我有一个列表是Ted=[“诸如此类] 所以基本上我想把输入转换成Ted,就是Ted lists = { "Ted": ["Blah", "Blahh"], "Joe": ["Foob", "zerx"], } name = input("What is your name?

我正在用python编写一个程序。为了提高程序的效率,我希望有一种方法可以接受用户输入并将其更改为列表的名称。基本上,就像去掉上面的引号

像这样
input=input(“你叫什么名字”)
假设你的名字是特德。 我有一个列表是
Ted=[“诸如此类]
所以基本上我想把输入转换成Ted,就是Ted

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],))
如果您使用的是Python2.x,请使用
raw_input
而不是
input

如果您使用的是Python2.x,请使用
raw_input
而不是
input

如果您使用的是Python2.x,请使用
raw_input
而不是
input


如果您使用的是Python 2.x,请使用
raw\u input
而不是
input

您可以试试字典:

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

阅读有关Internet上字典的更多信息。您不应该使用
input
作为变量名称,因为它是Python保留的关键字。

您可以尝试使用字典:

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

阅读有关Internet上字典的更多信息。您不应该使用
input
作为变量名称,因为它是Python保留的关键字。

您可以尝试使用字典:

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

阅读有关Internet上字典的更多信息。您不应该使用
input
作为变量名称,因为它是Python保留的关键字。

您可以尝试使用字典:

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

阅读有关Internet上词典的更多信息。您不应该使用
input
作为变量名称,因为它是Python保留的关键字。

我相信这是您想要的:

globals()['ted'] = 42
print(ted)

我相信这就是你想要的:

globals()['ted'] = 42
print(ted)

我相信这就是你想要的:

globals()['ted'] = 42
print(ted)

我相信这就是你想要的:

globals()['ted'] = 42
print(ted)

如果必须,为什么不使用字典?{'Ted':[Blah,Blahh]}我想Python版本是3.x?是的,使用字典。如果必须,为什么不使用字典?{'Ted':[Blah,Blahh]}我想Python版本是3.x?是的,使用字典。如果必须,为什么不使用字典?{'Ted':[Blah,Blahh]}我想Python版本是3.x?是的,使用字典。如果必须,为什么不使用字典?{'Ted':[Blah,Blahh]}我想Python版本是3.x?是的,使用字典。