[clug] Python Golf time

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


On Fri, 8 Apr 2016, Peter Barker wrote:

>> Shortest way to find the first file in a directory tree.
> filter(lambda x : x.endswith('.txt'), os.listdir("/tmp"))[0]
>> (the above of course only deals with one directory level)
> As does mine.

... this one does trees:

winner = (filter(lambda j : j.endswith(".TXT"), [ os.path.join(x[0],z) for 
z in  x[2] for x in os.walk("/tmp") ]))[0]

'though, frankly, I think we all lose with that.

>> 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