I am trying to flatten a list using list comprehension in python. My list is somewhat like
[[1, 2, 3], [4, 5, 6], 7, 8]
just for printing
You're trying to iterate through a number, which you can't do (hence the error).
If you're using python 2.7:
>>> from compiler.ast import flatten >>> flatten(l) [1, 2, 3, 4, 5, 6, 7, 8]
But do note that the module is now deprecated, and no longer exists in Python 3