Given this list
l = ['A','B','C','A']
how can I map it to a list of unique colors, e.g. ['red','blue','green']
without creating manually a dictionary?
The result would be
lc = ['red','blue','green','red']
Given this list
l = ['A','B','C','A']
how can I map it to a list of unique colors, e.g. ['red','blue','green']
without creating manually a dictionary?
The result would be
lc = ['red','blue','green','red']
If you want to map some value, you most likely want to use a dictionary:
colours = {"A": "red", "B": "blue", "C": "green"}
lc = [colours[v] for v in l]
As a result of which lc has this value:
['red', 'blue', 'green', 'red']