When it is required to chunk the tuples to 'N' values, list comprehension is used.
The list comprehension is a shorthand to iterate through the list and perform operations on it.
Below is a demonstration of the same −
my_tuple_1 = (87, 90, 31, 85,34, 56, 12, 5) print("The first tuple is :") print(my_tuple_1) N = 2 print("The value of 'N' has been initialized") my_result = [my_tuple_1[i : i + N] for i in range(0, len(my_tuple_1), N)] print("The tuple after chunking is : ") print(my_result)
The first tuple is : (87, 90, 31, 85, 34, 56, 12, 5) The value of 'N' has been initialized The tuple after chunking is : [(87, 90), (31, 85), (34, 56), (12, 5)]