我有这样的事情:
color_names = ('red', 'blue', 'orange', 'red')
Run Code Online (Sandbox Code Playgroud)
从上面的列表中我想做这样的事情:
colors = [(0, 'red'), (1, 'blue'), (2, 'orange')]
Run Code Online (Sandbox Code Playgroud)
每种颜色都应该是唯一的,这就是为什么我必须忽略第一个列表中的第二个"红色".我目前的解决方案有许多循环和条件.我正在寻找更好的解决方案.
python ×1