Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> can just be this in Python:

In PHP 5.3+ you can write:

    $image_urls = array_map(function($image) {return 'illos/'. $image['url'];}, $images);
Not as concise, but I'd postulate easier to read for people not familiar with list comprehensions.

In PHP 5.5+ there may be another way, but we're stuck with 5.3 in production for most clients, so I'm not up to speed.

> And, closures in Python -- and to be fair, just about any language that isn't PHP -- close over variables in the scope they're defined automatically, without having to use PHP's strange "use ($a, $b, $c)" construct.

Mmm, the debate of explicit or implicit scope? Explicit at least gets round those strange errors (hello Javascript) where you think you're referencing one thing... and actually referencing something else.



You can't write production Python and be unfamiliar with list comprehensions. They're a fundamental part of the language.


this

(javascript pun intended)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: