code: def to_unicode(data, encoding='UTF-8'):
      
      if isinstance(data, unicode_type):
          return data
  
      if isinstance(data, bytes):
          return unicode_type(data, encoding=encoding)
  
      if hasattr(data, '__iter__'):
          try:
              dict(data)
          except TypeError:
              pass
          except ValueError:
              # Assume it's a one dimensional data structure
              return (to_unicode(i, encoding) for i in data)
          else:
              # We support 2.6 which lacks dict comprehensions
              if hasattr(data, 'items'):
                  data = data.items()
              return dict(((to_unicode(k, encoding), to_unicode(v, encoding)) for k, v in data))
  
      return data
docs: Convert a number of different types of objects to unicode.