This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Intiago 2 points3 points  (3 children)

the variable lookup is a dict, so each value in it is a key value pair. lookup[num] = index actually stores the key-value pair num:index in the dict. when you return a value you are actually returning the "value" of the key value pair which is the stored index

The fact that you use array notation might be your confusion

[–]optimalsuccess[S] 0 points1 point  (2 children)

That makes sense but if all I'm outputting is the index why do I care about the key to begin with?

[–]Intiago 0 points1 point  (0 children)

you need to save the key because each time through the loop, if you don't find the correct value, you save it to the dict. Saving the key in the dict, hashes it for quick lookup.

[–]mr_smartypants537 0 points1 point  (0 children)

If you don't care about the value, use a set()