Ruby 看看这道题怎么做, $SAFE=4

sandect · March 20, 2014 · Last by david_w replied at March 24, 2014 · 2059 hits

http://www.alphasights.com/careers/apply/hong-kong/ruby-on-rails-developer

A local variable named log contains an array of hashes with timestamped events like so log = [ {time: 201201, x: 2}, {time: 201201, y: 7}, {time: 201201, z: 2}, {time: 201202, a: 3}, {time: 201202, b: 4}, {time: 201202, c: 0} ]

Please collapse the log by date into an array of hashes containing one entry per day [ {time: 201201, x: 2, y: 7, z: 2}, {time: 201202, a: 3, b: 4, c: 0}, ]

Ordering in the input is not defined. Ordering in the result is not important. Do not rely on the names of the hash keys other than :time. The field below executes your code in a Sandbox with $SAFE=4, so you can't define new classes, use global variables, etc.

log.group_by {|l| l[:time]}.values.map {|arr| arr.inject &:merge}

这道题,用 python 怎么实现?

You need to Sign in before reply, if you don't have an account, please Sign up first.