Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: Compairing filenames in a list

Reply
Thread Tools

Re: Compairing filenames in a list

 
 
Arnaud Delobelle
Guest
Posts: n/a
 
      09-30-2012
On 30 September 2012 02:27, Kevin Anthony <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Compairing filenames in a list Dave Angel Python 0 09-30-2012 01:41 AM
compairing rates but comparing credits? linda UK VOIP 1 09-13-2009 07:09 PM
Compairing PasswordQuestion Answers =?Utf-8?B?TWljaGFlbA==?= ASP .Net 2 04-02-2007 09:02 PM
compairing No without Operator sonu C Programming 17 03-18-2006 12:02 AM
problem with filenames, Filenames and FILENAMES B.J. HTML 4 04-23-2005 08:13 PM



Advertisments