Showing posts with label hash. Show all posts
Showing posts with label hash. Show all posts

Wednesday, 11 April 2018

Python: sort by value then key

No idea yet how this works, or why.

>>> d = {'apple': 7, 'banana': 3, 'almond': 7, 'peach': 4, 'beetroot': 3}
>>> sorted(d.iteritems(), key=lambda(k, v): (-v, k))
[('almond', 7), ('apple', 7), ('peach', 4), ('banana', 3), ('beetroot', 3)]

Tuesday, 26 January 2016

Ruby: multi-level hash keys trick

Ruby freakshow to allow multi-level hash keys to be set even if they have not been defined before. Feature!

m_entities = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }

Interview questions: 2020-12

Terraform provider vs provisioner Load balancing Network Load Balancer vs Application Load Balancer  Networking Layer 1 vs Layer 4 haproxy u...