You can try this,
colors = [
['orange', 'green'],
['orange', 'yellow'],
['purple', 'red'],
['brown', 'red']]
new_colors = []
isUnique = True
for pair in colors:
unique_colors = [new_color for new_pair in new_colors for new_color in new_pair]
for color in pair:
if color in unique_colors:
isUnique = False
break
if isUnique == True:
new_colors.append(pair)
isUnique = True
print(new_colors)
So,here first I declare an additional variable isUnique as flag and using a new list unique_colors which is inside the outer for loop, it is a flattened version of new_colors list and it will update each time new unique pair of color added to new_colors list.
Then inside the inner for loop, a checking took place for each color of the current pair. here if any color of the current pair matches any color of the unique_colors list, isUnique will be set False, and the inner loop will break.
After that isUnique will be checked and if it's True then the current pair will be added to new_colors and at the very last isUnique is to be set True for the next iteration.
Output : [['orange', 'green'], ['purple', 'red']]
['red', 'black'], would you want to keep it?