Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import Callable, Dict, Set, List
- def create_set(seq_str: str) -> Set[int]:
- """
- Takes a string of numbers separated by a single space and returns a set of integers.
- :param seq_str: A string containing a sequence of numbers separated by a single space.
- :return: A set of integer numbers
- """
- return {int(x) for x in seq_str.split()}
- def main():
- # Read input.
- set_1: set[int] = create_set(input())
- set_2: set[int] = create_set(input())
- n: int = int(input())
- # Define functions dictionary with appropriate type hints
- functions: Dict[str, Callable[[List[int]], None]] = {
- "Add First": lambda nums: set_1.update(nums),
- "Add Second": lambda nums: set_2.update(nums),
- "Remove First": lambda nums: set_1.difference_update(nums),
- "Remove Second": lambda nums: set_2.difference_update(nums),
- "Check Subset": lambda _: print(set_1.issubset(set_2) or set_2.issubset(set_1))
- }
- # Execute commands
- for _ in range(n):
- user_input: List[str] = input().split()
- current_command: str = f"{user_input[0]} {user_input[1]}"
- numbers: List[int] = [int(num) for num in user_input[2:]]
- functions[current_command](numbers)
- # Print output
- print(*sorted(set_1), sep=", ")
- print(*sorted(set_2), sep=", ")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement