可以遍历字典键吗?

huangapple go评论47阅读模式
英文:

Is it possible to iterate over dictionary keys?

问题

通过使用<dictionary_name>.keys字段,目前访问字典键的方法是通过该方法。但是,对于大型字典,这可能导致资源耗尽。我如何迭代字典的键,而不是将所有键作为数组返回?

英文:

The current method of accessing dictionary keys is through the use of the &lt;dictionary_name&gt;.keys field.

However, this may result in resource exhaustion for large dictionaries.

How can I iterate over the keys for the dictionary, instead of all the keys as an array?

答案1

得分: 2

Dictionaries have a fun forEachKey(_ function: ((K): Bool)): Void function.

英文:

Dictionaries have a fun forEachKey(_ function: ((K): Bool)): Void function.

huangapple
  • 本文由 发表于 2023年4月20日 00:55:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057058.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定