I expect the collection to be either a set or a dict. Problem is that:
for element in collection:
print element
will give me the elements if collection is a set, but indexes if collection is a dict. What I want is a one-liner that will iterate over dict values.
Is that possible?
The most foolproof way to test for a mapping is to use
isinstanceoncollections.Mapping:If you need to do that frequently (you shouldn’t, or you probably have a design issue), you could move it into a function: