Write a python program to create a list of tuples from given list having number and its cube in each tuple:
Answer:
list1 = [1, 2, 7, 8]
res = [(val, pow(val, 3)) for val in list1]
print(res)
Output:
[(1, 1), (2, 8), (7, 343), (8, 512)]
Answer:
list1 = [1, 2, 7, 8]
res = [(val, pow(val, 3)) for val in list1]
print(res)
Output:
[(1, 1), (2, 8), (7, 343), (8, 512)]
No comments:
Post a Comment