def _lower(v):
    """assumes that classes that inherit list, tuple or dict have a constructor
    that is compatible with those base classes. If you are using classes that
    don't satisfy this requirement you can subclass them and add a lower()
    method for the class"""
    if hasattr(v, "lower"):
        return v.lower()
    if isinstance(v, (list, tuple)):
        return v.__class__(_lower(x) for x in v)
    if isinstance(v, dict):
        return v.__class__(_lower(v.items()))
    return v
assumes that classes that inherit list, tuple or dict have a constructor
    that is compatible with those base classes. If you are using classes that
    don't satisfy this requirement you can subclass them and add a lower()
    method for the class