如何在 Julia 中遍历字典? [英] How to loop through a dictionary in Julia?

查看:28
本文介绍了如何在 Julia 中遍历字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Julia 中循环并打印字典的 (key, value) 对.我怎样才能做到这一点?

I want to loop through and print the (key, value) pairs of a dictionary in Julia. How can I do this?

我了解如何在这里用 Julia 初始化字典,但我也想遍历它.

I see how to initalize a dictionary in Julia here, but I want to loop through it as well.

推荐答案

解决方案比较简单:

x = Dict("a"=>"A", "b"=>"B", "c"=>"C")

for (key, value) in x
    print(key); print(value)
end

# Output: cCbBaA

查看 Base.Dict 的 Julia 文档了解更多关于你可以应用到 Julia 中的字典的函数!

Check out the Julia docs for Base.Dict to learn more about functions you can apply to a Dictionary in Julia!

这篇关于如何在 Julia 中遍历字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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