TRiBByX
8/22/2017 - 11:27 AM

Check if an item is iterable and iterate over it. Very nice for nested lists where you are unsure how many 'levels' of nested lists there ar

Check if an item is iterable and iterate over it. Very nice for nested lists where you are unsure how many 'levels' of nested lists there are

def iterate(data, indentation):
	if isinstance(data, dict):
		for key, value in data:
			print(key)
			if is_iterable(value):
				iterate(value, indentation+indent)
			else:
				pass
from collections import Iterable

def is_iterable(data):
	if isinstance(value, Iterable):
		return True
	else:
		return False