20 lines
762 B
Python
20 lines
762 B
Python
#!/usr/bin/env python3
|
|
"""Array intersection utility - returns sorted unique elements in both arrays."""
|
|
|
|
def array_intersection(arr1, arr2):
|
|
"""Return sorted list of unique elements present in both arrays."""
|
|
return sorted(set(arr1) & set(arr2))
|
|
|
|
if __name__ == "__main__":
|
|
import sys
|
|
# Parse arrays from command line: python script.py "1 2 3" "2 3 4"
|
|
if len(sys.argv) == 3:
|
|
a1 = list(map(int, sys.argv[1].split()))
|
|
a2 = list(map(int, sys.argv[2].split()))
|
|
result = array_intersection(a1, a2)
|
|
print(" ".join(map(str, result)))
|
|
else:
|
|
# Demo test case
|
|
arr1 = [1, 2, 3, 4, 5]
|
|
arr2 = [3, 4, 5, 6, 7]
|
|
print(f"Intersection of {arr1} and {arr2}: {array_intersection(arr1, arr2)}") |