Advertisement
Guest User

Untitled

a guest
Feb 12th, 2022
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.91 KB | None | 0 0
  1. from collections import deque
  2.  
  3. raw_string = deque(input().split())
  4. main_colours_model = ["red", "yellow", "blue"]
  5. secondary_colours_model = ["orange", "purple", "green"]
  6. colours_main = []
  7. colours_secondary = []
  8. all_colours = []
  9.  
  10. while raw_string:
  11.     if len(raw_string) == 1:
  12.         left_str = raw_string.popleft()
  13.         right_str = ''
  14.     else:
  15.         left_str = raw_string.popleft()
  16.         right_str = raw_string.pop()
  17.  
  18.     if left_str + right_str in main_colours_model:
  19.         colours_main.append(left_str + right_str)
  20.         all_colours.append(left_str + right_str)
  21.     elif right_str + left_str in main_colours_model:
  22.         colours_main.append(right_str + left_str)
  23.         all_colours.append(right_str + left_str)
  24.  
  25.     elif left_str + right_str in secondary_colours_model:
  26.         colours_secondary.append(left_str + right_str)
  27.         all_colours.append(left_str + right_str)
  28.     elif right_str + left_str in secondary_colours_model:
  29.         colours_secondary.append(right_str + left_str)
  30.         all_colours.append(right_str + left_str)
  31.  
  32.     else:
  33.         left_str = left_str[0:len(left_str) - 1]
  34.         right_str = right_str[0:len(right_str) - 1]
  35.         if left_str:
  36.             raw_string.insert(len(raw_string) // 2, left_str) # here
  37.         if right_str:
  38.             raw_string.insert(len(raw_string) // 2, right_str)
  39.  
  40. secondary_formation_dict = {
  41.     'orange': ['red', 'yellow'],
  42.     'purple': ['red', 'blue'],
  43.     'green': ['yellow', 'blue'],
  44. }
  45. result = []
  46.  
  47. for x in all_colours:
  48.     if x in colours_main:
  49.         result.append(x)
  50.     else:
  51.         is_valid = True
  52.         for k, v in secondary_formation_dict.items():
  53.             if k == x:  #here
  54.                 # print(secondary_formation_dict[k][::])
  55.                 contains_secondary = all([el in colours_main for el in v])
  56.                 if contains_secondary:
  57.                     result.append(k)
  58.  
  59. print(result)
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement