As long as the recursion limit of your installation is not reached, you can flatten nested lists by using this function: def flatten(o): if isinstance(o, list): nonlist = [x for x in o if not isinstance(x, list)] listelems = [x for x in o if isinstance(x, list)] listelems = [flatten(x) […]