←back to thread

104 points _ZeD_ | 4 comments | | HN request time: 0.674s | source
Show context
andy99 ◴[] No.44538191[source]

  def u(**kwargs):
    return tuple(kwargs.values())
Am I missing something, is this effectively the same?

*I realize the tuple can be omitted here

replies(4): >>44538290 #>>44538355 #>>44539536 #>>44539641 #
1. sischoel ◴[] No.44539536[source]
Or use itemgetter:

  >>> from operator import itemgetter
  >>> dct = {'greeting': 'hello', 'thing': 'world', 'farewell': 'bye'}
  >>> thing, greeting = itemgetter("thing", "greeting")(dct)
  >>> thing
  'world'
  >>> greeting
  'hello'
replies(3): >>44539632 #>>44540387 #>>44541901 #
2. ◴[] No.44539632[source]
3. giingyui ◴[] No.44540387[source]
There are so many things like this one in the standard library that it kinda pisses me off when I discover a new one.
4. notpushkin ◴[] No.44541901[source]
Ohhh, nice. Also, attrgetter (which also supports dotted notation to get nested attrs! Sadly, no dotted notation for itemgetter.)

https://docs.python.org/3/library/operator.html#operator.att...