+ 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 😊.
4 Respuestas
+ 3
Hi,
take list_1[0] item and give it his actual value and substracted by -1
list_1[0] = list[0] -1
+ 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
+ 2
Sorry for the tag my bad
But thanks I appreciate ur help😊
+ 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'