0

I want acces python lists with a hash:

hashtable = [] hashtable.append(132328df455b0028f13bf0abee51a63a: 'foo' ) 

But on execution it doesn`t accept the hash as an index:

python3 ./hdd/search.py File "./hdd/search.py", line 10 hashtable.append(132328df455b0028f13bf0abee51a63a: 'foo' ) SyntaxError: invalid syntax 

Is there a possibility to use the list with a hash?

Thanks in advance!

11
  • 3
    did you mean to use a dictionary? hashtable = {}; hashtable[132328df455b0028f13bf0abee51a63a] = 'foo'? Commented Dec 10, 2018 at 20:07
  • @hiroprotagonist I'd suggest making that an answer. OP could possibly want a list of dicts, but that doesn't seem feasible here with what's been provided. Commented Dec 10, 2018 at 20:14
  • yes, but after syntax correction it doesn`t work... Commented Dec 10, 2018 at 20:16
  • 1
    "I want acces python lists with a hash" well, you can't do that. Why don't you just use the hashmap data-structure, the dict? Commented Dec 10, 2018 at 20:16
  • What doesn't work? How are you accessing it? With what @hiroprotagonist suggested, you'd access the value by looking up the key (as opposed to an index number): print(hashtable['132328df455b0028f13bf0abee51a63a']) Commented Dec 10, 2018 at 20:21

1 Answer 1

1

the datatype that seems to fit your need seems to be the dictionary. you can use it this way:

hashtable = {} hashtable[0x132328df455b0028f13bf0abee51a63a] = 'foo' # or directly: # hashtable = {0x132328df455b0028f13bf0abee51a63a: 'foo'} 

and then access the values like this:

value = hashtable[0x132328df455b0028f13bf0abee51a63a] 

note hat 132328df455b0028f13bf0abee51a63a is not a valid python integer; you need to prefix hexadecimal numbers with 0x.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.