I was wondering how exactly the for
loop accesses keys in a dictionary ?
does it call dict.keys()
and iterate through that list ?
The reason I'm asking is that I want to query a dictionary's key, any key, and I was wondering if there is a difference in performance (aside from visuals and readability) between calling:
for key in dict:
my_func(dict[key])
break
and
my_func(dict.keys()[0])
Which brought me to the above question - what does python do during a for
loop on dict
s, specifically, under the hood?