[clug] Python Golf time

Peter Barker pbarker at barker.dropbear.id.au
Fri Apr 8 03:00:30 UTC 2016


On Fri, 8 Apr 2016, Andrew Janke wrote:

> Yes, Python.  I'm being forced off Perl.

No!  Don't do it!

> Shortest way to find the first file in a directory tree.
>
> Bonus points for finding a file of a specific mime type.  Everything
> I've tried uses os.walk or is like this:
>
>    for f in os.listdir(directory):
>        if f.endswith(".txt"):
>            winner = f
>            break

filter(lambda x : x.endswith('.txt'), os.listdir("/tmp"))[0]

Catching exceptions is left as an exercise etc etc.

> (the above of course only deals with one directory level)

As does mine.

> a

Yours,
-- 
Peter Barker                          |   Programmer,Sysadmin,Geek.
pbarker at barker.dropbear.id.au	      |   You need a bigger hammer.
:: It's a hack! Expect underscores! - Nigel Williams



More information about the linux mailing list