获取密钥由价值观,在一本字典 [英] Getting Keys by values , in a dictionary

查看:111
本文介绍了获取密钥由价值观,在一本字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能在一本字典执行以下操作,提供了我所有的值都是唯一的和无序。

How can I perform the following operations on a dictionary, provided all my values are unique and unsorted.

key : value
152 : 780
87 : 688
2165 : 15

  • 我想所有的钥匙。
  • 我要找到关键价值688
  • 我想获得的所有值。
  • pferably $ P $未经循环和无需维护在外部物体键值关系

    Preferably, without a loop and without having to maintain the key-value relation in an external object.

    有时候我会想念,蟒蛇这些样的东西。

    I sometimes miss, python for these sort of things.

    推荐答案

    如果该键是整数值,阵列可能会有所帮助。它是一种稀疏阵列;所以对于和已分配一个值,每个只处理键(我不知道关于内存的使用虽然)。

    If the keys are integer values, Array might help. It is a sparse array; so for and for each will only process keys that have been assigned a value (I have no idea about memory usage though).

    所以:

    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方法来获取键的值;有没有简单的函数来获取所有按键虽然。

    There is a indexOf method to get the key for a value; there is no simple function to get all keys though.

    这篇关于获取密钥由价值观,在一本字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆