On 30 September 2012 02:27, Kevin Anthony <kevin.s.anth...@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