Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import deque
- main_colors = {"red", "yellow", "blue"}
- secondary_colors = {"orange", "purple", "green"}
- subcolors_dict = {"orange": ["red", "yellow"], "purple": ["red", "blue"], "green": ["yellow", "blue"]}
- collected_colors = []
- text = deque(input().split())
- while text:
- start_string = text.popleft()
- end_string = text.pop() if text else ""
- variant_1 = start_string + end_string
- variant_2 = end_string + start_string
- if variant_1 in main_colors or variant_1 in secondary_colors:
- collected_colors.append(variant_1)
- continue
- elif variant_2 in main_colors or variant_2 in secondary_colors:
- collected_colors.append(variant_2)
- continue
- else:
- if start_string[:-1]:
- text.insert(len(text) // 2, start_string[:-1])
- if end_string[:-1]:
- text.insert(len(text) // 2, end_string[:-1])
- for color in collected_colors:
- if color in secondary_colors:
- for needed_color in subcolors_dict[color]:
- if needed_color not in collected_colors:
- while color in collected_colors:
- collected_colors.remove(color)
- break
- print(collected_colors)
Advertisement
Add Comment
Please, Sign In to add comment