I'm new to coding and python is the first course I'm working through from beginning to end.
I'm working on exercise 18 "Using a list of lists in a function"
The aim is to create a function called flatten that takes a single list and concatenates all the sublists that are part of it into a single list.
I receive the following error message when trying to run the code below:
Traceback (most recent call last):
File "python", line 28, in
File "python", line 21, in flatten
TypeError: 'int' object is not iterable
Am I trying to apply something here that just is not suited to the task? Is the original solution viable, or is some variation of the second solution better, and why?
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]] """If I use the code below, I can complete the exercise. However, I want to use a range as we have been doing throughout this course. As I understand it, it's a better approach to use. def flatten(lists): results =  for numbers in lists: for items in numbers: results.append(items) print results return results print flatten(n) """ #the code below here is what I am trying to get to work, but it doesn't work. def flatten(lists): results =  for numbers in range(len(lists)): for items in numbers: results.append(items) print results return results print flatten(n)