【发布时间】:2016-11-21 10:53:20
【问题描述】:
我有两个这样的哈希:
hash1 = Hash.new
hash1["part1"] = "test1"
hash1["part2"] = "test2"
hash1["part3"] = "test3"
hash2 = Hash.new
hash2["part1"] = "test1"
hash2["part2"] = "test2"
hash2["part3"] = "test4"
预期输出:part3
基本上,我想迭代两个哈希并打印出"part3",因为"part3" 的值在哈希中是不同的。我可以保证两个哈希的键相同,值可能不同。我想在它们的值不同时打印出键?
我曾尝试一次迭代两个哈希并比较值,但似乎没有给出正确的解决方案。
【问题讨论】:
-
欢迎来到 Stack Overflow。请阅读“How to Ask”,包括链接页面和“minimal reproducible example”。我们希望看到你努力的证据。目前看来您还没有尝试过,并要求我们为您编写代码。 meta.stackoverflow.com/q/261592/128421 读起来很有用。
标签: ruby