def tuplize ( nested ) : if isinstance ( nested , str ) : return nested try : return tuple ( map ( tuplize , nested ) ) except TypeError : return nested
python recursion on nested list to tuple
Recursively converts iterables into tuples .
def tuplize(nested):
  """Recursively converts iterables into tuples.

  Args:
    nested: A nested structure of items and iterables.

  Returns:
    A nested structure of items and tuples.
  """
  if isinstance(nested, str):
    return nested
  try:
    return tuple(map(tuplize, nested))
  except TypeError:
    return nested