小编vku*_*zma的帖子

如何确保多维数组中的唯一值?

我有这样的事情:

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

0
推荐指数
1
解决办法
534
查看次数

标签 统计

python ×1