Pythonic way to access arbitrary element from dictionary [duplicate]

Similar to your second solution, but slightly more obvious, in my opinion:

return next(iter(dictionary.values()))

This works in python 2 as well as in python 3, but in python 2 it’s more efficient to do it like this:

return next(dictionary.itervalues())

Leave a Comment