Sorry for the title, my problem is as follows. I have a list of paths and I want to get multiple common prefixes. For example, given I have:
['/usr/local/lib/python2.7/dist-packages/pkg_name-0.1-py2.7.egg/pkg_name',
'/usr/local/lib/python2.7/dist-packages/pkg_name-0.1-py2.7.egg/EGG-INFO',
'/usr/bin/pkg_name']
I want to have:
['/usr/local/lib/python2.7/dist-packages/pkg_name-0.1-py2.7.egg/',
'/usr/bin/pkg_name']
Because the first two have a common prefix that is a directory. Hope I made this clear,
rubik
EDIT: The paths I have are Python eggs and some executables. I want to remove the entire egg, not the directories inside it, like EGG-INFO or pkg_name. So it has to be /usr/.../dist-packages/pkg_name-0.1-py2.7.egg/. The other path, since it is an executable remains as it is.
Thank you
The problem is not well-defined. What do you want to have in this case:
Shall it be one
/usror two:/usr/bin/usr, or three?In either case, the algorithm will be like this:
os.path.commonprefix()with 2nd, 3rd, …, i-th until common prefix is not/; that will be your first group