Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!usr/local/bin/python3.8
- # -*- coding: utf-8 -*import
- from _collections import deque
- MAIN = ('red', 'yellow', 'blue')
- SECONDARY = {
- 'orange': ('red', 'yellow'),
- 'purple': ('red', 'blue'),
- 'green': ('yellow', 'blue'),
- }
- text = deque(input().split())
- colors = []
- while True:
- if not text:
- break
- if len(text) > 1:
- first_sub_string = text[0]
- last_sub_string = text[-1]
- word = first_sub_string + last_sub_string
- word_2 = last_sub_string + first_sub_string
- if word in MAIN or word in SECONDARY:
- colors.append(word)
- del text[0]
- del text[-1]
- elif word_2 in MAIN or word_2 in SECONDARY:
- colors.append(word_2)
- del text[0]
- del text[-1]
- else:
- first_sub_string = text.popleft()[:-1]
- last_sub_string = text.pop()[:-1]
- middle = len(text) // 2
- if last_sub_string:
- text.insert(middle, last_sub_string)
- if first_sub_string:
- text.insert(middle + 1, first_sub_string)
- else:
- word = text[0]
- if word in MAIN or word in SECONDARY:
- colors.append(word)
- text.pop()
- else:
- text.pop()
- for x in colors:
- if x in SECONDARY:
- main_1 = SECONDARY[x][0]
- main_2 = SECONDARY[x][1]
- if main_1 not in colors or main_2 not in colors:
- colors.remove(x)
- print(colors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement