+ 2

How to subtract an item in list and replace the result from which it was subtracted

Suppose : List_1 = [50] What I am not able to do here is to subtract one(1) from "index 0 of list_1" , Then replace that resulted value from index 0 of list_1. If someone has an answer or solution how they can code it, then please write it with explanation. Thank you 😊.

25th Mar 2020, 6:21 AM
Mirza Ishan Beg
Mirza Ishan Beg - avatar
4 Respostas
+ 3
Hi, take list_1[0] item and give it his actual value and substracted by -1 list_1[0] = list[0] -1
25th Mar 2020, 6:33 AM
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎
Oneill~Онеилл~奥尼尔~ओनील~اونیل~*‎ - avatar
+ 2
Just like you can access an element of a list by index print(List_1[0]) #outputs 50 You can also assign it a value List_1[0] = any_value Now I guess you can do the rest on your own
25th Mar 2020, 6:32 AM
XXX
XXX - avatar
+ 2
Sorry for the tag my bad But thanks I appreciate ur help😊
25th Mar 2020, 6:59 AM
Mirza Ishan Beg
Mirza Ishan Beg - avatar
+ 1
It's not list_1 = list_1(0) - 1 You have to use square brackets list_1 = list_1[0] - 1 And according to me, it should be list_1[0] = list_1[0] - 1 Because in your code, the whole list would be changed, not the first value of the list. Also please change the tag of this question from 'python' to 'ruby'
25th Mar 2020, 6:56 AM
XXX
XXX - avatar