I am trying to remove the floating point in the tuple using a lambda function. I am slicing the tuple and converting the last element in the tuple to int and concatenating it.
xyz = list((filter(lambda x : x[2].is_integer(), sides_triplet )))
print(xyz)
xy = list(map(lambda tup : tup[:2] + (int(tup[2]),), xyz))
print(xy)
Output:
[(3, 4, 5.0), (6, 8, 10.0)]
[(3, 4, 5), (6, 8, 10)]
The code works perfectly fine but my question is on the line:
xy = list(map(lambda tup : tup[:2] + (int(tup[2]),), xyz))
Need explanation as to why we use comma and then close the braces after int. Instead if I use the line below, it throws an error, why is that?
xy = list(map(lambda tup : tup[:2] + (int(tup[2])), xyz))
Output:
xy = list(map(lambda tup : tup[:2] + (int(tup[2])), xyz))
TypeError: can only concatenate tuple (not "int") to tuple