英文:
Is it possible to iterate over dictionary keys?
问题
通过使用<dictionary_name>.keys
字段,目前访问字典键的方法是通过该方法。但是,对于大型字典,这可能导致资源耗尽。我如何迭代字典的键,而不是将所有键作为数组返回?
英文:
The current method of accessing dictionary keys is through the use of the <dictionary_name>.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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论