How to add a number to one element inside a tuple in a nested list of tuples by row and col in Python

1 Answer

0 votes
# Create a nested list of tuples
data = [
    [(1, 2), (3, 4)],
    [(5, 6), (7, 8)],
    [(9, 10), (11, 12)]
]

r, c = 0, 1
a, b = data[r][c]
data[r][c] = (a, b + 100)

for i in range(len(data)):
    print(f"Row {i}:", data[i])




'''
run:

Row 0: [(1, 2), (3, 104)]
Row 1: [(5, 6), (7, 8)]
Row 2: [(9, 10), (11, 12)]

'''

 



answered Feb 9 by avibootz

Related questions

...