Finding duplicate file names and modifying them based on elements of the path larry.martell at
Thu Jul 19 00:20:51 CEST 2012

I have an interesting problem I'm trying to solve. I have a solution
almost working, but it's super ugly, and know there has to be a
better, cleaner way to do it.

I have a list of path names that have this form:


I need to find all the file names (basenames) in the list that are
duplicates, and for each one that is a dup, prepend dir4 to the
filename as long as the dir4/file pair is unique. If there are
multiple dir4/files in the list, then I also need to add a sequence
number based on the sorted value of dir5 (which is a date in ddMONyy

For example, if my list contains:


Then I want to end up with:


My solution involves multiple maps and multiple iterations through the
data. How would you folks do this?

More information about the Python-list mailing list