w3resource logo
Python Exercises

Python Exercise: Replace last value of tuples in a list

Python tuple: Exercise-21 with Solution

Sample Solution:-

Python Code:

l = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
print([t[:-1] + (100,) for t in l])

Sample Output:

[(10, 20, 100), (40, 50, 100), (70, 80, 100)] 

Python Code Editor:

l = [(10, 20, 40), (40, 50, 60), (70, 80, 90)]
print([t[:-1] + (100,) for t in l])

Improve this sample solution and post your code through Disqus