2
如何在字典上执行以下操作(前提是我的所有值都是唯一的和未排序的)。通过值获取键,在字典中
key : value
152 : 780
87 : 688
2165 : 15
- 我想所有的密钥。
- 我想查找关键值688
- 我想获取所有值。
优选地,没有循环并且不必在外部对象中维持键 - 值关系。
我有时会错过,python的这些东西。
如何在字典上执行以下操作(前提是我的所有值都是唯一的和未排序的)。通过值获取键,在字典中
key : value
152 : 780
87 : 688
2165 : 15
优选地,没有循环并且不必在外部对象中维持键 - 值关系。
我有时会错过,python的这些东西。
如果键是整数值,Array可能会有所帮助。它是一个稀疏阵列;所以为和每个将只处理已被分配一个值的键(虽然我不知道内存使用情况)。
所以:
var list: Array = [];
list[1] = 10;
list[4] = 40;
for each(var value: int in list) trace(value);
// outputs (order can be different)
// 10
// 40
// index has to be * or String; the compiler gives an error if it is not
for(var index: * in list) trace(index);
// outputs (order can be different)
// 1
// 4
有一个方法的indexOf来获取的值的键;没有简单的功能来获得所有的密钥。
如果没有迭代你的字典的代价,你无法做任何事情。所以维护另一个对象似乎是你需要做的。
我认为这是你想要的,以前在这个线程中回答: http://stackoverflow.com/questions/2386793/efficient-looping-through-as3-dictionary –