Advertisement
Guest User

paint_color

a guest
Apr 8th, 2020
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. substr = input().split()
  2.  
  3. main_colors = ['red', 'yellow', 'blue']
  4. secondary_colors = {'orange': ['red', 'yellow'], 'purple': ['red', 'blue'], 'green': ['yellow', 'blue']}
  5. found = []
  6. added = ''
  7.  
  8. while substr:
  9.     if len(substr) > 1:
  10.         first = substr[0]
  11.         l_f = len(first)
  12.         last = substr[-1]
  13.         l_l = len(last)
  14.         if (first + last) in main_colors or (first + last) in secondary_colors:
  15.             added = first + last
  16.             found.append(added)
  17.             substr.pop(0)
  18.             substr.pop()
  19.         elif (last + first) in main_colors or (last + first) in secondary_colors:
  20.             added = last + first
  21.             found.append(added)
  22.             substr.pop(0)
  23.             substr.pop()
  24.         else:
  25.             if l_l > 1:
  26.                 last = last[:len(last)-1]
  27.                 substr = substr[:(len(substr) // 2)] + [last] + substr[len(substr) // 2:]
  28.             substr.pop()
  29.  
  30.             if l_f > 1:
  31.                 first = first[:len(first)-1]
  32.                 substr = substr[:(len(substr) // 2)] + [first] + substr[len(substr) // 2:]
  33.             substr.pop(0)
  34.             # added = first + last
  35.             # added = added[1:len(added) - 1]
  36.  
  37.     else:
  38.         added = substr.pop()
  39.         if added in main_colors or added in secondary_colors:
  40.             found.append(added)
  41.         else:
  42.             break
  43.  
  44. for color, main in secondary_colors.items():
  45.     if color in found:
  46.         if main[0] not in found or main[1] not in found:
  47.             found.remove(color)
  48. print(found)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement