frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Dict Unpacking in Python

https://github.com/asottile/dict-unpacking-at-home
48•_ZeD_•3d ago

Comments

zdimension•4h ago
Did not know that such things could be accomplished by registering a new file coding format. Reminds me of https://pypi.org/project/goto-statement/
zahlman•4h ago
This one is arguably even more of a hack; it's working at the source code level rather than the AST level.

The "coding" here is a bytes-to-text encoding. The Python lexer expects to see character data; you get to insert arbitrary code to convert the bytes to characters (or just use existing schemes the implement standards like UTF-8).

nine_k•4h ago
In short, it runs a text preprocessor as the source text decoder (like you would decode from Latin-1 or Shift-JIS to Unicode).
zelphirkalt•3h ago
I found dictionary unpacking to be quite useful, when you don't want to mutate things. Code like:

    new_dict = {**old_dict, **update_keys_and_values_dict}
Or even complexer:

    new_dict = {
        **old_dict,
        **{
            key: val
            for key, val in update_keys_and_values_dict
            if key not in some_other_dict
        }
    }
It is quite flexible.
peter422•2h ago
I love the union syntax in 3.9+:

  new_dict = old_dict | update_keys_and_values_dict
parpfish•1h ago
Don’t forget the in place variant!

  the_dict |= update_keys_and_values_dict
sco1•3h ago
The author also has an accompanying video: https://youtu.be/eqiM0xRmFJg
andy99•3h ago

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

*I realize the tuple can be omitted here

Grikbdl•3h ago
Yours relies on ordering, OP's presumably does not.
Izkata•2h ago
You have to pull them out by key name, and not just get everything. Here's a working version, though with a totally different syntax (to avoid having to list the keys twice, once as keys and once as resulting variable names):

  >>> def u(locals, dct, keys):
  ...     for k in keys:
  ...         locals[k] = dct[k]
  ... 
  >>> dct = {'greeting': 'hello', 'thing': 'world', 'farewell': 'bye'}
  >>> u(locals(), dct, ['greeting', 'thing'])
  >>> greeting
  'hello'
  >>> thing
  'world'
  >>> farewell
  Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
  NameError: name 'farewell' is not defined

Modifying locals() is generally frowned upon, as there's no guarantee it'll work. But it does for this example.
kristjansson•19m ago
While not nearly as fun as the OP, I’d note that this sort of unpacking is very pleasant in the newish PEP636 match case statements:

https://peps.python.org/pep-0636/#matching-builtin-classes

OpenAI’s Windsurf deal is off, and Windsurf’s CEO is going to Google

https://www.theverge.com/openai/705999/google-windsurf-ceo-openai
456•rcchen•6h ago•306 comments

ETH Zurich and EPFL to release a LLM developed on public infrastructure

https://ethz.ch/en/news-and-events/eth-news/news/2025/07/a-language-model-built-for-the-public-good.html
344•andy99•9h ago•44 comments

Replication of Quantum Factorisation Records with an 8-bit Home Computer [pdf]

https://eprint.iacr.org/2025/1237.pdf
25•sebgan•1h ago•1 comments

Faking a JPEG

https://www.ty-penguin.org.uk/~auj/blog/2025/03/25/fake-jpeg/
109•todsacerdoti•4h ago•26 comments

Preliminary report into Air India crash released

https://www.bbc.co.uk/news/live/cx20p2x9093t
156•cjr•7h ago•251 comments

jank is C++

https://jank-lang.org/blog/2025-07-11-jank-is-cpp/
200•Jeaye•10h ago•69 comments

FEMA Didn’t Answer Thousands of Calls From Flood Survivors

https://www.nytimes.com/2025/07/11/climate/fema-missed-calls-texas-floods.html
49•standardUser•57m ago•9 comments

Tell HN: uBlock Origin on Chrome is finally gone

68•ipsum2•2h ago•34 comments

A software conference that advocates for quality

https://bettersoftwareconference.com/
56•leoncaet•6h ago•31 comments

Dict Unpacking in Python

https://github.com/asottile/dict-unpacking-at-home
48•_ZeD_•3d ago•11 comments

HDD Clicker generates HDD clicking sounds, based on HDD Led activity

https://www.serdashop.com/HDDClicker
34•starkparker•3h ago•14 comments

Leveraging Elixir's hot code loading capabilities to modularize a monolithic app

https://lucassifoni.info/blog/leveraging-hot-code-loading-for-fun-and-profit/
8•ronxjansen•3d ago•1 comments

Andrew Ng: Building Faster with AI [video]

https://www.youtube.com/watch?v=RNJCfif1dPY
176•sandslash•1d ago•46 comments

Bill Atkinson's psychedelic user interface

https://patternproject.substack.com/p/from-the-mac-to-the-mystical-bill
381•cainxinth•16h ago•203 comments

Upgrading an M4 Pro Mac mini's storage for half the price

https://www.jeffgeerling.com/blog/2025/upgrading-m4-pro-mac-minis-storage-half-price
314•speckx•13h ago•199 comments

Measuring power network frequency using junk you have in your closet

https://halcy.de/blog/2025/02/09/measuring-power-network-frequency-using-junk-you-have-in-your-closet/
20•zdw•5h ago•3 comments

Astronomers race to study interstellar interloper

https://www.science.org/content/article/astronomers-race-study-interstellar-interloper
108•bikenaga•12h ago•56 comments

Repaste Your MacBook

https://christianselig.com/2025/07/repaste-macbook/
185•speckx•15h ago•89 comments

Apple vs the Law

https://formularsumo.co.uk/blog/2025/apple-vs-the-law/
346•tempodox•21h ago•350 comments

Activeloop (YC S18) Is Hiring AI Search and Python Back End Engineers(Onsite,MV)

https://careers.activeloop.ai/
1•davidbuniat•6h ago

Monorail – Turn CSS animations into interactive SVG graphs

https://muffinman.io/monorail/
50•stanko•3d ago•5 comments

Introduction to Digital Filters

https://ccrma.stanford.edu/~jos/filters/
38•ofalkaed•8h ago•7 comments

Computer Scientists Figure Out How to Prove Lies

https://www.quantamagazine.org/computer-scientists-figure-out-how-to-prove-lies-20250709/
12•pseudolus•2d ago•1 comments

'123456' password exposed chats for 64M McDonald's job applicants

https://www.bleepingcomputer.com/news/security/123456-password-exposed-chats-for-64-million-mcdonalds-job-applicants/
82•nan60•6h ago•46 comments

Show HN: RULER – Easily apply RL to any agent

https://openpipe.ai/blog/ruler
54•kcorbitt•10h ago•9 comments

Lead pigment in turmeric is the culprit in a global poisoning mystery (2024)

https://www.npr.org/sections/goats-and-soda/2024/09/23/nx-s1-5011028/detectives-mystery-lead-poisoning-new-york-bangladesh
315•perihelions•12h ago•156 comments

At Least 13 People Died by Suicide Amid U.K. Post Office Scandal, Report Says

https://www.nytimes.com/2025/07/10/world/europe/uk-post-office-scandal-report.html
567•xbryanx•15h ago•482 comments

OpenAI delays launch of open weights model

https://twitter.com/sama/status/1943837550369812814
61•martinald•2h ago•50 comments

AWS Free Tier Changes on July 15, 2025

https://freetier.co/articles/aws-free-tier-changes-july-15-2025
9•coop182•4h ago•1 comments

2-4 wire converters / hybrids (2009)

https://sound-au.com/appnotes/an010.htm
10•userbinator•4d ago•1 comments