How to add a number to one tuple in a row of a nested list of tuples by index 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 = 1, 0
a, b = data[r][c]
data[r][c] = (a + 10, b + 10)

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




'''
run:

Row 0: [(1, 2), (3, 4)]
Row 1: [(15, 16), (7, 8)]
Row 2: [(9, 10), (11, 12)]

'''

 



answered Feb 9 by avibootz

Related questions

2 answers 156 views
...