考虑以下文件列表
/wr_vjxeacn/lzx/vjx/rkkelkwrvkjl.o
/wr_vjxeacn/lzx/vjx/wllnxncvr.o
/wr_hvlx/lzx/hvlx/wlxkjjlnr/Sbisln.xww
/wr_hvlx/lzx/wllqepse/lzx/xww/ANTLR/evi
/wr_hvlx/lzx/wllqepse/lzx/xww/ANTLR/zajrvhn/sjrez3x.cee
/wr_hvlx/lzx/wllqepse/lzx/xww/ivj/GNUhstnmven
/wr_hvlx/eklr+mkajc/sjrez3x64.evi.7ss153m930724031i252iic841n68i6i
/wr_hvlx/lzx/wllqepse/lzx/xww/ANTLR/evi/sjrez3x.evi
/wnkwenrkkel/lzx
/wnkwenrkkel/lzx/GNUhstnmven.xkhhkj
/wnkwenrkkel/lzx/GNUhstnmven.cnwl
/wnkwenrkkel/lzx/GNUhstnmven.evlr
/wnkwenrkkel/lzx/GNUhstnmven.gvjckgl-vs32
我想弄清楚的是使用公共前缀dirname
对项目进行分组的最佳方式common prefix dirname = os.path.dirname(os.path.commonprefix(...))
所以理想情况下,在分组后,上面应该看起来像
/wr_vjxeacn/lzx/vjx
/wr_vjxeacn/lzx/vjx/rkkelkwrvkjl.o
/wr_vjxeacn/lzx/vjx/wllnxncvr.o
*************************************************************
/wr_hvlx/lzx/hvlx
/wr_hvlx/lzx/hvlx/wlxkjjlnr/Sbisln.xww
*************************************************************
/wr_hvlx/lzx/wllqepse
/wr_hvlx/lzx/wllqepse/lzx/xww/ANTLR/evi
/wr_hvlx/lzx/wllqepse/lzx/xww/ANTLR/zajrvhn/sjrez3x.cee
/wr_hvlx/lzx/wllqepse/lzx/xww/ivj/GNUhstnmven
*************************************************************
/wr_hvlx/eklr+mkajc
/wr_hvlx/eklr+mkajc/sjrez3x64.evi.7ss153m930724031i252iic841n68i6i
*************************************************************
/wr_hvlx/lzx/wllqepse/lzx/xww/ANTLR/evi
/wr_hvlx/lzx/wllqepse/lzx/xww/ANTLR/evi/sjrez3x.evi
*************************************************************
/wnkwenrkkel
/wnkwenrkkel/lzx
*************************************************************
/wnkwenrkkel/lzx
/wnkwenrkkel/lzx/GNUhstnmven.xkhhkj
/wnkwenrkkel/lzx/GNUhstnmven.cnwl
/wnkwenrkkel/lzx/GNUhstnmven.evlr
/wnkwenrkkel/lzx/GNUhstnmven.gvjckgl-vs32
我尝试了什么
itertools.groupby
,但它没有前瞻或后瞻。动机
我有一个已签入文件的列表,我希望根据模块对这些文件进行分组,以识别各个模块所有者。