Advertisement
simeonshopov

Paint Colors

Jun 8th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. #!usr/local/bin/python3.8
  2. # -*- coding: utf-8 -*import
  3. from _collections import deque
  4.  
  5. MAIN = ('red', 'yellow', 'blue')
  6. SECONDARY = {
  7.     'orange': ('red', 'yellow'),
  8.     'purple': ('red', 'blue'),
  9.     'green': ('yellow', 'blue'),
  10. }
  11.  
  12.  
  13. text = deque(input().split())
  14. colors = []
  15.  
  16. while True:
  17.     if not text:
  18.         break
  19.     if len(text) > 1:
  20.         first_sub_string = text[0]
  21.         last_sub_string = text[-1]
  22.         word = first_sub_string + last_sub_string
  23.         word_2 = last_sub_string + first_sub_string
  24.         if word in MAIN or word in SECONDARY:
  25.             colors.append(word)
  26.             del text[0]
  27.             del text[-1]
  28.         elif word_2 in MAIN or word_2 in SECONDARY:
  29.             colors.append(word_2)
  30.             del text[0]
  31.             del text[-1]
  32.         else:
  33.             first_sub_string = text.popleft()[:-1]
  34.             last_sub_string = text.pop()[:-1]
  35.             middle = len(text) // 2
  36.             if last_sub_string:
  37.                 text.insert(middle, last_sub_string)
  38.             if first_sub_string:
  39.                 text.insert(middle + 1, first_sub_string)
  40.     else:
  41.         word = text[0]
  42.         if word in MAIN or word in SECONDARY:
  43.             colors.append(word)
  44.             text.pop()
  45.         else:
  46.             text.pop()
  47.  
  48. for x in colors:
  49.     if x in SECONDARY:
  50.         main_1 = SECONDARY[x][0]
  51.         main_2 = SECONDARY[x][1]
  52.         if main_1 not in colors or main_2 not in colors:
  53.             colors.remove(x)
  54. print(colors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement