Demonstrate your mastery of Python collections!
Create a function rotate_list(lst, k) that rotates a list to the right by k positions.
For example, rotating [1, 2, 3, 4, 5] by 2 gives [4, 5, 1, 2, 3].
Requirements:
Use modulo (%) to handle k larger than list length. Slicing with negative indices makes this elegant: lst[-k:] + lst[:-k]
Create a function count_unique(lst) that returns a tuple containing:
Use sets to find unique elements efficiently!
Convert to set for unique elements, then sorted() for the sorted list. Return as a tuple: (len(unique_set), sorted(unique_set))
Create a function merge_tuples(t1, t2) that takes two tuples of equal length and returns a list of tuples, where each tuple contains elements from the same index.
This is essentially implementing the zip() function!
Requirements:
Use min(len(t1), len(t2)) to find the shorter length. Loop through indices and create tuples: [(t1[i], t2[i]) for i in range(min_len)]