Skip to content

Home

Spread list

Flattens a list, by spreading its elements into a new list.

def spread(arg):
  ret = []
  for i in arg:
    ret.extend(i) if isinstance(i, list) else ret.append(i)
  return ret

spread([1, 2, 3, [4, 5, 6], [7], 8, 9]) # [1, 2, 3, 4, 5, 6, 7, 8, 9]

More like this

Start typing a keyphrase to see matching snippets.