Advertisement
exDotaPro

paint_colors

Jul 29th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. def concatenate(str_1, str_2, arr):
  5.     valid_color = ''
  6.     if str_1 + str_2 in arr:
  7.         valid_color = str_1 + str_2
  8.     elif str_2 + str_1 in arr:
  9.         valid_color = str_2 + str_1
  10.     return valid_color
  11.  
  12.  
  13. def cut_char(str_1, str_2):
  14.     new_str_1, new_str_2 = '', ''
  15.     if len(str_1) > 0:
  16.         new_str_1 = str_1[:-1]
  17.     if len(str_2) > 0:
  18.         new_str_2 = str_2[:-1]
  19.     return new_str_1, new_str_2
  20.  
  21.  
  22. def filter_colors(colors):
  23.     if 'orange' in colors and not all(x in colors for x in ['yellow', 'red']):
  24.         colors.remove('orange')
  25.     if 'purple' in colors and not all(x in colors for x in ['blue', 'red']):
  26.         colors.remove('purple')
  27.     if 'green' in colors and not all(x in colors for x in ['yellow', 'blue']):
  28.         colors.remove('blue')
  29.     return colors
  30.  
  31.  
  32. string = input().split()
  33.  
  34. all_colors = ['yellow', 'blue', 'red', 'orange', 'purple', 'green']
  35. collection = deque(string)
  36. result = []
  37.  
  38. while collection:
  39.     first_elem, second_elem = collection.popleft(), ''
  40.     if collection:
  41.         second_elem = collection.pop()
  42.  
  43.     color = concatenate(first_elem, second_elem, all_colors)
  44.  
  45.     if color:
  46.         result.append(color)
  47.     else:
  48.         first_return, second_return = cut_char(first_elem, second_elem)
  49.         idx_to_return = len(collection) // 2
  50.         if first_return:
  51.             collection.insert(idx_to_return, first_return)
  52.         if second_return:
  53.             collection.insert(idx_to_return, second_return)
  54.  
  55. print(filter_colors(result))
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement