data structures - dictionary or map with either string or integer as key in python? -


this might silly question, reason solution escapes me @ moment.

i have fast , efficient access data in list format. example list of questions:

q = {} q[1] = "my first string" q[2] = "my second string" q[3] = "my third string" 

i can find question 2's string doing q[2]. retrieve question number indexing q string:

q["my second string"] -> gives 2 answer 

i without iterating on keys (defeats purpose of dictionary) , avoid defining second dictionary using string key avoid wasted memory. possible?

ultimately reason access q[2] or q["my second string"] , data associated question 2, whether using number or string key data. possible without having iterating on keys while avoiding data duplication?

there's no problem having mixture of int , str keys

>>> q = {} >>> q[1] = "my first string" >>> q[2] = "my second string" >>> q[3] = "my third string" >>> q.update({v:k k,v in q.items()}) >>> q["my second string"] 2 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c++ - Using OpenSSL in a multi-threaded application -

All overlapping substrings matching a java regex -