i want one-dimensional list of values several keys list of dicts.
that's how in ruby:
irb> list_ = [{a:1, b:2, c:3}, {a:4, b:5, c:6}] irb> list_.flat_map{ |dict_| dict_.values_at :b, :c } => [2, 3, 5, 6]
now how in python?
i this:
>>> lst = [{'a': 1, 'b': 2, 'c': 3}, {'a': 4, 'b': 5, 'c': 6}] >>> [dct[i] dct in lst in ('b', 'c')] [2, 3, 5, 6]
Comments
Post a Comment