This Python tuple program will add a tuple of values as row-wise elements in the tuple matrix.
Input:
A = [[(‘sqa’, 4)], [(‘tools’, 8)]]
B = (3,6)
Output:
[[(‘sqa’, 4,3)], [(‘tools’, 8,6)]]
var_a = [[('sqa', 4)], [('tools', 8)]]
var_b = (3, 6)
print("Input A : ", var_a)
print("Input B : ", var_b)
output = []
# initiate a loop till length of var_a
for i in range(len(var_a)):
# get tuple value with the help of indexing of var_a and connvert into list
l1 = list(var_a[i][0])
# check if value of i is less than length of var_b
if i < len(var_b):
# append new value to the list
l1.append(var_b[i])
# now convert list into tuple and append to output list
output.append([tuple(l1)])
print(output)
Output:
Input A : [[('sqa', 4)], [('tools', 8)]]
Input B : (3, 6)
Output :
[[('sqa', 4, 3)], [('tools', 8, 6)]]