请查看以下输入,并帮助我将其转换为以下输出
输入:
arr = [{"Key1"=>1, "key3"=>1}, {"Key2"=>3, "Key4"=>0}, {"Key1"=>1, "Key4"=>1},
{"Key2"=>3, "key3"=>0}, {"Key1"=>3, "Ke5"=>0}]
期望的输出:
[{"Key1"=>1}, {"Key2"=>1}, {"Key3"=>3}, {"Key4"=>0}, {"Key1"=>1},
{"Key4"=>1}, {"Key3"=>3}, {"Key2"=>0}, {"Key1"=>3}, {"Key5"=>0}]
答案 0 :(得分:2)
试试这个:
data.flat_map(&:to_a).map { |k, v| {k => v} }