You're passing the result of somedict.keys()
to the function. In Python 3, dict.keys
doesn't return a list, but a set-like object that represents a view of the dictionary's keys and (being set-like) doesn't support indexing.
To fix the problem, use list(somedict.keys())
to collect the keys, and work with that.