Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.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 - Fatal编程技术网

python:使用哈希值的列表访问

python:使用哈希值的列表访问,python,Python,我希望使用哈希访问python列表: hashtable = [] hashtable.append(132328df455b0028f13bf0abee51a63a: 'foo' ) 但在执行时,它不接受哈希作为索引: python3 ./hdd/search.py File "./hdd/search.py", line 10 hashtable.append(132328df455b0028f13bf0abee51a63a: 'foo' ) SyntaxError: invalid

我希望使用哈希访问python列表:

hashtable = []
hashtable.append(132328df455b0028f13bf0abee51a63a: 'foo' )
但在执行时,它不接受哈希作为索引:

python3 ./hdd/search.py
  File "./hdd/search.py", line 10
hashtable.append(132328df455b0028f13bf0abee51a63a: 'foo' )
SyntaxError: invalid syntax
是否有可能将列表与哈希一起使用


提前谢谢

似乎适合您需要的数据类型是。您可以这样使用它:

hashtable = {}
hashtable[0x132328df455b0028f13bf0abee51a63a] = 'foo'
# or directly:
# hashtable = {0x132328df455b0028f13bf0abee51a63a: 'foo'}
然后访问如下值:

value = hashtable[0x132328df455b0028f13bf0abee51a63a]

请注意,132328df455b0028f13bf0abee51a63a不是有效的python整数;您需要在十六进制数字前加上0x。

您的意思是使用字典吗?哈希表={};hashtable[132328df455b0028f13bf0abee51a63a]=“foo”?@hiroprogator我建议你回答这个问题。OP可能想要一个dict列表,但这在这里似乎不可行。是的,但在语法更正后它就不起作用了…我想要用散列访问python列表,你不能这样做。为什么不使用hashmap数据结构,dict?什么不起作用?您如何访问它?按照@hiroprotation的建议,您可以通过查找键而不是索引号来访问该值:printhashtable['132328df455b0028f13bf0abee51a63a']