Parallelize a list consolidation in Python -
i have sorted list of "box definitions" consolidate. list looks like:
big_list = [\ # ... # ... [3, 4, 5, 4, 5, 6, 65],\ [3, 4, 5, 4, 5, 6, 60],\ [3, 4, 5, 4, 5, 6, 55],\ [3, 4, 5, 4, 5, 6, 52],\ [3, 4, 5, 4, 5, 6, 23],\ [3, 4, 5, 4, 5, 6, 17],\ [3, 4, 5, 4, 5, 6, 0],\ [5, 8, 9, 6, 9, 10, 90],\ [5, 8, 9, 6, 9, 10, 84],\ [5, 8, 9, 6, 9, 10, 32],\ [5, 8, 9, 6, 9, 10, 0],\ # ... # ... [750, 800, 900, 751, 801, 901, 97],\ [750, 800, 900, 751, 801, 901, 24],\ [750, 800, 900, 751, 801, 901, 17],\ [750, 800, 900, 751, 801, 901, 16],\ [750, 800, 900, 751, 801, 901, 0]\ # ... # ... ]
where box "format" is: [x1, y1, z1, x2, y2, z2, attribute], , can assume dx=1, dy=1, dz=1
also, can assume list has been sorted like:
big_list=sorted(big_list, key=lambda n:n[6], reverse=true) big_list=sorted(big_list, key=lambda n:n[2]) big_list=sorted(big_list, key=lambda n:n[1]) big_list=sorted(big_list, key=lambda n:n[0])
the list may several millions of items long, , reduce list discrete "box" gets highest "attribute"...so in case like:
reduced_big_list = [\ [3, 4, 5, 4, 5, 6, 65],\ [5, 8, 9, 6, 9, 10, 90],\ [750, 800, 900, 751, 801, 901, 97]\ ]
the method using on list like:
i = 0 while < len(big_list)-1: if big_list[i][0]==big_list[i+1][0]\ , big_list[i][1]==big_list[i+1][1]\ , big_list[i][2]==big_list[i+1][2] \ , big_list[i][6] >= big_list[i+1][6]: del big_list[i+1] else: i=i+1
the problem when list "long" (10 million+ "boxes"), process very, slow.
is there clever way parallelize list "decimation" process or perhaps quicken process?
the slowness call del
, moves items of complete tail of list 1 step. in case, don't use del
. make instead new list, starting empty list , append
ing items want keep.
Comments
Post a Comment