SHARE
TWEET

Untitled

a guest Aug 12th, 2017 43 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # find unique non-contiguous subsets of a list
  2. def subSegment(patterns, span, positions, segments, loop=0, level=0):
  3.     if level < span:
  4.         for loop in range(level, len(patterns)):
  5.             # a stack of positions
  6.             positions.append(loop)
  7.             # recursive call
  8.             segments = subSegment(patterns, span, positions, segments, loop+1, level+1)
  9.     else:
  10.         segment = [p for p in positions]
  11.         # if no duplicates in the segment
  12.         if len(list(set(segment))) == len(segment):
  13.             #if not duplicate:    # ignore duplicates
  14.             if segment not in segments:
  15.                 segments.append(segment)
  16.  
  17.     if positions:
  18.         positions.pop()
  19.  
  20.     return segments
RAW Paste Data
Top