不同路径之间的多个公共前缀
抱歉标题,我的问题如下。我有一个路径列表,我想获得多个公共前缀。例如,假设我有:
['/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']
我想要有:
['/usr/local/lib/python2.7/dist-packages/pkg_name-0.1-py2.7.egg/',
'/usr/bin/pkg_name']
因为前两个有一个共同的前缀,即目录。希望我说清楚了,
rubik
编辑:我的路径是 Python Egg 和一些可执行文件。我想删除整个 Egg,而不是其中的目录,例如 EGG-INFO
或 pkg_name
。所以它必须是 /usr/.../dist-packages/pkg_name-0.1-py2.7.egg/
。另一个路径,因为它是可执行文件,所以保持原样。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题没有明确定义。在这种情况下,您想要什么:
是一个
/usr
还是两个:/usr/bin
/usr
还是三个?无论哪种情况,算法都将如下所示:
/
;这将是您的第一组The problem is not well-defined. What do you want to have in this case:
Shall it be one
/usr
or 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