Overview
Remove duplicates and find what two collections have in common with Python sets.
- set() keeps each item once
- & finds items in both sets
- | combines, - subtracts
Short Course
A set keeps each item only once and has no order. & keeps what is in
both sets, | combines them.
a = set(["py", "web", "py"]) # {'py', 'web'}
b = {"web", "db"}
print(a & b) # {'web'}
print(sorted(a | b)) # ['db', 'py', 'web']
print(sorted(a - b)) # ['py']
Task
Write common_tags(a, b) that returns the tags found in both lists, each
once, as a sorted list.
Test Suites
Pending
Stdout