[clug] Python Golf time

Andrew Janke a.janke at gmail.com
Fri Apr 8 03:20:18 UTC 2016


Unless we've somehow switched to Haskell (that seems to know whatever
you dont want it to do and heads down that path irrespective -- hi
Carlo!) I think you need an input directory in there somewhere?


a

On 8 April 2016 at 13:18, Hal Ashburner <hal at ashburner.info> wrote:
> import glob
> winner = glob.glob('*.txt')[0]
>
> On 8 April 2016 at 11:25, Andrew Janke <a.janke at gmail.com> wrote:
>> Yes, Python.  I'm being forced off Perl.
>>
>>
>> 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
>>
>> (the above of course only deals with one directory level)
>>
>>
>> a
>>
>> --
>> linux mailing list
>> linux at lists.samba.org
>> https://lists.samba.org/mailman/listinfo/linux



More information about the linux mailing list