I've gotten this function to work without list comprehension, however, I was wondering how to do it with one:
def flatten(L):
a_list = []
for i in L:
if isinstance(i, list):
gl = flatten(i)
for n in gl:
a_list.append(n)
else:
a_list.append(i)
return a_list
# This is how I've attempted to use list comprehension, but I get a Syntax
# error and I'm not sure why.
return [n for n in flatten(i) if isinstance(i, list) else i for i in L]