'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.…
Kristen Bell leaves A-listers baffled as her opening monologue devolves into 'cringe' musical number at Actor Awards 2026
Timothee Chalamet brings his mom as his date to Actor Awards 2026... as girlfriend Kylie Jenner skips red carpet
Spiders could be cause of 'false sewage alerts' from Anglian Water sensors
Spiders could be cause of 'false sewage alerts' from Anglian Water sensors
The busy Essex roundabout among the most 'stressful' for drivers in Britain
EU chief is mocked for waiting until TODAY to address crisis in the Middle East
KHADIJA KHAN: Pakistan outlawed 'family voting' - why is it OK here?
Albanian gangs flood Britain with illegal cigarettes: How Balkan criminals are using social media to sell smuggled tobacco for 'express delivery' to British homes
RAF typhoon shoots down Iranian drone 'heading for Qatar'
UK government's Vulnerability Monitoring System is working - fixes flow far faster
Infosec In Brief DNS vulnerabilities are being addressed 84 percent faster in the UK public sector thanks to an automated vulnerability scanning system established as part of a program kicked off early last year.…