def include(gset, elem, value=True):
    """Do whatever it takes to make ``elem in gset`` true.

        >>> L, S, D = [ ], set(), { }
        >>> include(L, "Lucy"); include(S, "Sky"); include(D, "Diamonds");
        >>> print L, S, D
        ['Lucy'] set(['Sky']) {'Diamonds': True}

    Works for sets (using ``add``), lists (using ``append``) and dicts (using
    ``__setitem__``).

    ``value``
        if ``gset`` is a dict, does ``gset[elem] = value``.

    Returns ``elem``, or raises an Error if none of these operations are supported.
    """
    add = getattr(gset, 'add', None) # sets
    if add is None: add = getattr(gset, 'append', None)  # lists
    if add is not None: add(elem)
    else: # dicts
        if not hasattr(gset, '__setitem__'):
            raise Error("gset is not a supported container.")
        gset[elem] = value
    return elem
def include ( gset , elem , value = True ) : add = getattr ( gset , 'add' , None ) if add is None : add = getattr ( gset , 'append' , None ) if add is not None : add ( elem ) else : if not hasattr ( gset , '__setitem__' ) : raise Error ( "gset is not a supported container." ) gset [ elem ] = value return elem
Do whatever it takes to make ``elem in gset`` true.

        >>> L, S, D = [ ], set(), { }
        >>> include(L, "Lucy"); include(S, "Sky"); include(D, "Diamonds");
        >>> print L, S, D
        ['Lucy'] set(['Sky']) {'Diamonds': True}

    Works for sets (using ``add``), lists (using ``append``) and dicts (using
    ``__setitem__``).

    ``value``
        if ``gset`` is a dict, does ``gset[elem] = value``.

    Returns ``elem``, or raises an Error if none of these operations are supported.