python - Groupby files based on common prefix -
consider next set of file listings
/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
what trying figure out optimal way of grouping items mutual prefix dirname
common prefix dirname = os.path.dirname(os.path.commonprefix(...))
so ideally after grouping above should like
/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
what have tried
itertools.groupby
, not have lookahead or lookbehind. iterating , breaking on prefix change. cannot find working solution consider border cases motivation
i have list of checked in files want grouping based on modules identify respective module owners.
python python-2.7 group-by
No comments:
Post a Comment