Hello,

Is there any way to access a large number of keys in a dictionary efficiently. Perhaps via indexing with an array of lookup values. Some pseudo code may help;

dictionary={a:1, b:2, c:3 ...etc}
lookup=[a, a, b, c, c ... etc]
print dictionary[lookup]

thanks, Joe

dictionary exists just for that purpose.

And you first want to check that the index is in the dictionary to avoid an error message.

dictionary={a:1, b:2, c:3 ...etc}
lookup=[a, a, b, c, c ... etc]
results = [dictionary[key] for key in lookup if key in dictionary]
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.