Add the value 5 at the end of the list/tuple

Asked

Viewed 33 times

0

lista_da_tupla_a=(["0", "33", "40"], ["8", "30","9"], ["7", "0", "0"])

lista_da_tupla_a = list

lista_da_tupla_a[2] = "5"

print(lista_da_tupla_a)

Desired exit: (["0", "33","5"], ["8","30",5], ["7","0","5"])

1 answer

0


I think what you want is this:

lista_da_tupla_a = (["0", "33", "40"], ["8", "30","9"], ["7", "0", "0"])
for tuplinha in lista_da_tupla_a:
    tuplinha[2] = "5"
print(lista_da_tupla_a)

I mean, you use the for to go through each trio and replace the third element with "5".

Here’s the way out:

(['0', '33', '5'], ['8', '30', '5'], ['7', '0', '5'])

See here working on ideone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.