Lists and functions: using a list of lists in a function giving indentation error


#1


where am i going wrong with the indentation?


#2

is your return lined up with the for


#3

Don’t mix indentation between spaces and tabs. Try to erase all of them and make 4 spaces or 1 tab indentation for each block.


#4

I took the code from codecademy using “get code”, then i removed all the tabs and placed the following tabs:
def: 0 tabs
results: 1 tab
for numbers: 2 tabs
for number: 3 tabs
results.append: 4 tabs
return: 1 tab

This was my error report:
File “python”, line 6
for numbers in lists:
^
IndentationError: unexpected indent
Thanks in advance


#5

is it a bug then?
(filling the minimum of 20 characters here)


#6

Could you post the link to the exercise? Only if you haven’t solved it yet or keep getting the same issue.


#7

i have solved it by hitting get code, but i did try again and got the same error. this is the url:
https://www.codecademy.com/courses/learn-python/lessons/lists-and-functions/exercises/using-a-list-of-lists-in-a-function?action=lesson_resume
but i suppose it won’t refer to my code.
how can i copy and paste my code to this forum while keeping the indentation?


#8

#9
n = [[1, 2, 3], [4, 5, 6, 7, 8, 9]]
# Add your function here

def flatten(lists):
	results = []
		for numbers in lists:
			for number in numbers:
				results.append(number)
	return results

print flatten(n)

#10

You have a extra indentation at the first for, therefore, you should remove it and the same for the next two lines.

Indentation is supposed to delimiter code blocks, not only for improve readability. In this case, the extra indentation at the first for means you are putting everything as part of results code, but that’s not a sub-function for python to work properly.


#11

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.