Untitled
unknown
plain_text
a year ago
512 B
4
Indexable
def find_common_elements(v1, v2): # Convert lists to sets to find common elements efficiently set1 = set(v1) set2 = set(v2) # Find intersection of two sets common_elements = set1.intersection(set2) # Sort the common elements sorted_common_elements = sorted(common_elements) # Return the sorted list return sorted_common_elements # Example usage: v1 = [1, 2, 3, 4, 5] v2 = [3, 4, 5, 6, 7] result = find_common_elements(v1, v2) print("Common elements:", result)
Editor is loading...
Leave a Comment