Moment drug driver admits he is high on ketamine minutes after mowing down and killing motorcyclist as he's jailed for 10 years
Muslim gunman who killed two and wounded 14 in Texas bar 'terrorist' attack kept photos of Iranian leaders and a flag in his home
Actor Awards 2026 best dressed: Kristen Bell sizzles alongside Gwyneth Paltrow, Emma Stone and Demi Moore as they lead glamour on the red carpet
Michelle Williams seen for first time since James Van Der Beek's death as she wins Actor Award
'Do not approach' and call 999 if you see missing man last seen in Chelmsford
Inside the tiny hilltop town in Italy with incredible views - and a narrow alleyway that people can't fit through
CodeSOD: Popping Off
Python is (in)famous for its "batteries included" approach to a standard library, but it's not that notable that it has plenty of standard data structures, like dicts. Nor is in surprising that dicts have all sorts of useful methods, like pop, which removes a key from the dict and returns its value.
Because you're here, reading this site, you'll also be unsurprised that this doesn't stop developers from re-implementing that built-in function, badly. Karen sends us this:
def parse_message(message): def pop(key): if key in data: result = data[key] del data[key] return result return '' data = json.loads(message) some_value = pop("some_key") # <snip>...multiple uses of pop()...</snip>Here, they create an inner method, and they exploit variable hoisting. While pop appears in the code before data is declared, all variable declarations are "hoisted" to the top. When pop references data, it's getting that from the enclosing scope. Which while this isn't a global variable, it's still letting a variable cross between two scopes, which is always messy.
Also, this pop returns a default value, which is also something the built-in method can do. It's just the built-in version requires you to explicitly pass the value, e.g.: some_value = data.pop("some_key", "")
Karen briefly wondered if this was a result of the Python 2 to 3 conversion, but no, pop has been part of dict for a long time. I wondered if this was just an exercise in code golf, writing a shorthand function, but even then- you could just wrap the built-in pop with your shorthand version (not that I'd recommend such a thing). No, I think the developer responsible simply didn't know the function was there, and just reimplemented a built-in method badly, as so often happens.
.comment { border: none;} [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.UK draws up overland rescue plan for 94,000 Britons trapped in Gulf states: As PM lets US troops use British bases to launch strikes on Iran, ministers prepare for a mass evacuation of tourists and expats via Saudi Arabia
Catherine O'Hara leaves Hollywood audience in tears as late star wins posthumous trophy at 2026 Actor Awards
The long lost Essex railway station that’s now part of a nature reserve
Lenovo Unveils an Attachable AI Agent 'Companion' for Their Laptops
Read more of this story at Slashdot.
OpenAI’s Altman says Pentagon set ‘scary precedent’ binning Anthropic
OpenAI has signed a deal with the United States Department of War (DoW) that allows use of its advanced AI systems in classified environments, and urged the Pentagon to make the same terms available to its rivals.…