Changing an item in a list using a for loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Changing an item in a list using a for loop

for x in some_list: if x == 0: change x to something

2nd Jul 2018, 6:20 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
5 Answers
+ 4
Hi David Gedalia Ordman Could you please state your question. Having trouble? Read this: https://www.sololearn.com/discuss/1316935/?ref=app
2nd Jul 2018, 6:25 PM
Agent
Agent - avatar
+ 1
David Gedalia Ordman , do you know how get a value from list? lets say.. how do i print 5 from list = [1,2,2,4,5,6,3,8] ?
2nd Jul 2018, 7:05 PM
Qwertiony
Qwertiony - avatar
0
@Qwertiony print (list[4])
3rd Jul 2018, 2:36 PM
David Gedalia Ordman
David Gedalia Ordman - avatar
0
David Gedalia Ordman , Pro!!! Now, with this knowledge, how can you make this 5 become 9? in a way that print(list[4]) will outout 9.
3rd Jul 2018, 2:47 PM
Qwertiony
Qwertiony - avatar
0
you should just write list[4] = 9 and if you use print ( list ) you’ll see the difference
11th Jul 2018, 11:02 AM
Ibrahim Maroquino
Ibrahim Maroquino - avatar