New values are not registred in the list


Hey guys,

I want to print directly the new list with the print my_list right after the for loop but it still print me the old list with the non doubled numbers.

my_list = [1,9,3,8,5,7]

for number in my_list:
	print 2*number

print my_list  #This line should print the new my_list with the new values
	       # [1,9,3,8,5,7] => [2,18,6,16,10,14]
	       # I want it to print the new list


How is this going to end up in the list?


You're right, that's just a print but how to print the list with doubled numbers ?


First you need to create it. Either by modifying the original list in place, or by spawning a new list. Do not print inside the loop.


Okay I got it. This is the next exercice: " More with 'for' ".
I did it and I got it.

Thanks for the reply :grinning:


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