def iterate_items(obj):
    """Iterates over the object's key value pairs (key, value), where obj[key] == value."""
    if hasattr(obj, "items"):
        return obj.items()
    # If the object lacks the items() function, assume it's a list with keys [0, len(obj)-1].
    return enumerate(obj)