|
| 1 | +""" |
| 2 | +input_=> [1, 2, 3, 4, 77, 78, 79, 88, 89, 100, 101, 102, 103, 200, 201, 202, 4321] |
| 3 | +flat_list_=> [1, 1, 1, 73, 1, 1, 9, 1, 11, 1, 1, 1, 97, 1, 1, 4119] |
| 4 | +cut_locations_=> [3, 6, 8, 12, 15] |
| 5 | +==================== |
| 6 | +[[1, 2, 3, 4]] |
| 7 | +[[1, 2, 3, 4], [77, 78, 79]] |
| 8 | +[[1, 2, 3, 4], [77, 78, 79], [88, 89]] |
| 9 | +[[1, 2, 3, 4], [77, 78, 79], [88, 89], [100, 101, 102, 103]] |
| 10 | +[[1, 2, 3, 4], [77, 78, 79], [88, 89], [100, 101, 102, 103], [200, 201, 202]] |
| 11 | +[[1, 2, 3, 4], [77, 78, 79], [88, 89], [100, 101, 102, 103], [200, 201, 202], [4321]] |
| 12 | +==================== |
| 13 | +loot_=> [[1, 2, 3, 4], [77, 78, 79], [88, 89], [100, 101, 102, 103], [200, 201, 202], [4321]] |
| 14 | +""" |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +def flatten_gap(list): |
| 19 | + ''' |
| 20 | + flattens list making sequential numbers into 1 |
| 21 | + ''' |
| 22 | + list.sort() |
| 23 | + gap = [] |
| 24 | + while (len(list) > 1): |
| 25 | + first = list.pop(0) |
| 26 | + second = list[0] |
| 27 | + gap.append(abs(second - first)) |
| 28 | + return gap |
| 29 | + |
| 30 | +def get_cut_position(flat_list): |
| 31 | + ''' |
| 32 | + returns a list containing where to cut positions should be. |
| 33 | + if number!= 1 cut here |
| 34 | + ''' |
| 35 | + return [i for i, x in enumerate(flat_list) if x != 1] |
| 36 | + |
| 37 | + |
| 38 | +def cut_list(list,cut_positions): |
| 39 | + ''' |
| 40 | + [1, 2, 3, 4, 77, 78, 79, 88, 89, 100, 101, 102, 103, 200, 2001, 2002] # list start with |
| 41 | + [3, 6, 8, 12, 13] # cut list at these spots |
| 42 | + cuts # cut start |
| 43 | + cute # cut end |
| 44 | + ''' |
| 45 | + print '=='*10 |
| 46 | + new_list = [] |
| 47 | + cuts = 0 |
| 48 | + |
| 49 | + for cute in cut_positions: |
| 50 | + new_list.append(list[cuts:cute+1]) |
| 51 | + cuts = cute+1 |
| 52 | + |
| 53 | + print new_list |
| 54 | + |
| 55 | + new_list.append(list[cuts:]) |
| 56 | + print new_list |
| 57 | + print '==' * 10 |
| 58 | + return new_list |
| 59 | + |
| 60 | +points = [1,2,3,4,77,78,79,88,89,100,101,102,103,200,201,202,4321] |
| 61 | +tmp = tuple(points) |
| 62 | + |
| 63 | +flat_list = flatten_gap(points) |
| 64 | +cut_positions = get_cut_position(flat_list) |
| 65 | + |
| 66 | +points = list(tmp) |
| 67 | +print 'input_=>',points |
| 68 | +print 'flat_list_=>',flat_list |
| 69 | +print 'cut_locations_=>',cut_positions |
| 70 | + |
| 71 | +loot = cut_list(points,cut_positions) |
| 72 | +print 'loot_=>',loot |
0 commit comments