[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: Compairing filenames in a list
From:       Arnaud Delobelle <arnodel () gmail ! com>
Date:       2012-09-30 22:08:32
Message-ID: CAJ6cK1b4tN7cLH2FWLLS=O_M78UdXnLK_KAC8Sg4T-2aPGjwCg () mail ! gmail ! com
[Download RAW message or body]

On 30 September 2012 02:27, Kevin Anthony <kevin.s.anthony@gmail.com> wrote:
> I have a list of filenames, and i need to find files with the same name,
> different extensions, and split that into tuples.  does anyone have any
> suggestions on an easy way to do this that isn't O(n^2)?

> > > import os, itertools
> > > filenames = ["foo.png", "bar.csv", "foo.html", "bar.py"]
> > > dict((key, tuple(val)) for key, val in itertools.groupby(sorted(filenames), \
> > > lambda f: os.path.splitext(f)[0]))
{'foo': ('foo.html', 'foo.png'), 'bar': ('bar.csv', 'bar.py')}

-- 
Arnaud
-- 
http://mail.python.org/mailman/listinfo/python-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic