Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- substr = input().split()
- main_colors = ['red', 'yellow', 'blue']
- secondary_colors = {'orange': ['red', 'yellow'], 'purple': ['red', 'blue'], 'green': ['yellow', 'blue']}
- found = []
- added = ''
- while substr:
- if len(substr) > 1:
- first = substr[0]
- l_f = len(first)
- last = substr[-1]
- l_l = len(last)
- if (first + last) in main_colors or (first + last) in secondary_colors:
- added = first + last
- found.append(added)
- substr.pop(0)
- substr.pop()
- elif (last + first) in main_colors or (last + first) in secondary_colors:
- added = last + first
- found.append(added)
- substr.pop(0)
- substr.pop()
- else:
- if l_l > 1:
- last = last[:len(last)-1]
- substr = substr[:(len(substr) // 2)] + [last] + substr[len(substr) // 2:]
- substr.pop()
- if l_f > 1:
- first = first[:len(first)-1]
- substr = substr[:(len(substr) // 2)] + [first] + substr[len(substr) // 2:]
- substr.pop(0)
- # added = first + last
- # added = added[1:len(added) - 1]
- else:
- added = substr.pop()
- if added in main_colors or added in secondary_colors:
- found.append(added)
- else:
- break
- for color, main in secondary_colors.items():
- if color in found:
- if main[0] not in found or main[1] not in found:
- found.remove(color)
- print(found)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement