Python: Lists and Dictionaries #9


#1



Stuck on lists and dictionaries, I keep getting this error and am not sure why. I looped, appended, and sorted as instructed.

Oops, try again. It looks like square_list has 2 at index 1 instead of 4.


start_list = [5, 3, 1, 2, 4]  #list_name and items(variable)
square_list = []

for x in start_list: #for variable in list_name
    print x ** 2
    square_list.append(x)

square_list.sort()

print square_list


#2

Check your indentation there. Move one tab space inward.


#3

I just figrued it out, changed to square_list.append(x ** 2) and resolved my own problem. :slight_smile:


#4

That's right but also correct the indentation.

start_list = [5, 3, 1, 2, 4]
square_list = []

# Your code here!
for x in start_list:
    square_list.append(x**2)
    square_list.sort()
    print square_list

#5

it printed as intended, are the indentations still necessary? and why?

25
9
1
4
16
[1, 4, 9, 16, 25]
None


#6

when I indent results look like this:

25
[25]
9
[9, 25]
1
[1, 9, 25]
4
[1, 4, 9, 25]
16
[1, 4, 9, 16, 25]
None

Both ways allow me to move on the the next section


#7

Well, when I did as suggested, I got

[25]
[9, 25]
[1, 9, 25]
[1, 4, 9, 25]
[1, 4, 9, 16, 25]
None

Never mind.

Have fun coding! :slight_smile:


#8

ok, thanks for the suggestion :slight_smile:


#9

tart_list = [5, 3, 1, 2, 4]
square_list = []
for x in start_list:
test = x**2
square_list.insert(x,test)
square_list.sort()

print square_list