如果原子在值列表中,是否有一种通过原子值查找字典键的简洁方法?
假设:字典的值列表具有每个唯一元素
例:
d:`tech`fin!(`aapl`msft;`gs`jpm) / would like to get key `fin by looking up `jpm
d?`gs`jpm / returns `fin as expected
d?`jpm / this doesn't work unfortunately
$[`jpm in d`fin;`fin;`tech] / this is the only way I can come up with
Run Code Online (Sandbox Code Playgroud)
最后一个选项不能很好地扩展键的数量
谢谢!
您可以利用where词典的操作方式,并使用in:
where `jpm in/:d
,`fin
Run Code Online (Sandbox Code Playgroud)
请注意,这将返回一个列表,因此first如果要复制上面的内容,可能需要对输出执行此操作.
| 归档时间: |
|
| 查看次数: |
658 次 |
| 最近记录: |