

9·
1 month agoInside the lambda
expression you can have a comprehension to unpack the keys
list to get the same sort of uplet as your “manual” example, like this:
>>> items = [{"core_name": "a", "label": "b"},{"core_name": "c", "label": "d"}, ]
>>> keys = ["core_name", "label"]
>>> tuple(items[0][k] for k in keys)
('a', 'b')
>>> sorted(items, key=lambda d: tuple(d[k] for k in keys))
[{'core_name': 'a', 'label': 'b'}, {'core_name': 'c', 'label': 'd'}]
This is the behaviour of inet_aton, which ping uses to translate ASCII representations of IPv4 addresses to a 32 bit number. Its manpage: https://man7.org/linux/man-pages/man3/inet_aton.3.html
It recognizes the usual quad decimal notation of course, but also addresses of the form a.b.c or a.b, or in this instance, a, with is taken to be a 32bit number.
Each part can also be written in hex or octal, with the right prefix, such that 10.012.0x800a is as valid form for 10.10.128.10.
Not all software use inet _aton to translate ASCII addresses. inet_pton for instance (which understands both v4 and v6) doesn’t