18/18 AttributeError: 'NoneType' object has no attribute 'append'
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
def flatten(lists):
results = []
for i in range(0,len(lists)):
results = results.append(lists[i])
return results
print flatten(n)
Traceback (most recent call last): File “python”, line 10, in
Anyone know what is wrong?
Answer 531f073352f863ed72002f0f
I got this to work:
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
# Add your function here
def flatten(lists):
results = []
for numbers in lists:
for x in numbers:
results.append(x)
return results
print flatten(n)
1 comments
thankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyouthankyou
Answer 531f639280ff33cd91004dce
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
def flatten(lists):
results = []
for i in range(0,len(lists)):
results = results.append(lists[i])
return results
print flatten(n)
This way you are basically trying to append lists inside results.
Variable n is a list of lists! Which means when you iterate through n it will simply return more lists! To get elements you need to iterate inside the list which is already located inside an list.
1 comments
For some reason, I can’t get the range method to work for this lesson. I feel like I did the same thing as above but I used “x” instead of “i” for the variable name in the for loop.
Answer 531fc23e548c35d81a004bce
Answer 531fdaa6548c35cbc10073cc
Ah i see, so it’s like n[1] = [ 1, 2, 3] n[2] = [ 4, 5, 6, 7, 8, 9]
Okay, I think I get it now.
2 comments
It’s exactly like that! => if you want to know how is it possible check out pointers in C,
me too :(
Answer 55ed3d5786f55274b700056e
This is the Correct answer.
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
def flatten(lists):
results = [ ]
for numbers in lists:
print numbers
for i in numbers:
print i
results.append(i)
return results
print flatten(n)
Popular free courses
- Free course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner Friendly4 Lessons - Free course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner Friendly11 Lessons - Free course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner Friendly6 Lessons