Traversing a multidimensional structure and applying strip() to all strings
I don't understand why you are checking for an __iter__ attribute, as you don't seem to use it. However I would recommend a couple of changes:


Use Abstract Base Classes in the collections module to test duck types, such as "Iterable"
Use types.StringTypes to detect string types


.

import collections
import types

def strip_spaces( item ):
    if isinstance( item, types.StringTypes ):
        return item.strip()

    if isinstance( item, collections.Iterable ):
        if isinstance( item, list ):
            return [ strip_spaces( value ) for value in item ]

        elif isinstance( item, dict ):
            return dict([ ((strip_spaces(key), strip_spaces(value)) \
                                    for key, value in item.iteritems() ])

        elif isinstance( item, tuple ):
            return tuple( [ strip_spaces( value ) for value in item ] )

    return item