def to_tuple(x):
    """Converts lists to tuples.

    For example::

        >>> from networkx.utils import to_tuple
        >>> a_list = [1, 2, [1, 4]]
        >>> to_tuple(a_list)
        (1, 2, (1, 4))

    """
    if not isinstance(x, (tuple, list)):
        return x
    return tuple(map(to_tuple, x))