Split a list of MatchSteps into multiple lists, each denoting a single MATCH traversal.
189172
def _split_match_steps_into_match_traversals(match_steps):
    """"""
    output = []
    current_list = None
    for step in match_steps:
        if isinstance(step.root_block, QueryRoot):
            if current_list is not None:
                output.append(current_list)
            current_list = [step]
        else:
            current_list.append(step)

    if current_list is None:
        raise AssertionError(u'current_list was unexpectedly None: {}'.format(match_steps))
    output.append(current_list)

    return output
418112
def matchSubset(**kwargs):
        """"""
        ret = []
        for m in self.matches:
            allMatched = True
            for k,v in iteritems(kwargs):
                mVal = getattr(m, k)
                try:
                    if v == mVal or v in mVal: continue # this check passed
                except Exception: pass # if attempting to check __contains__ and exception is raised, it's assumed to be false
                allMatched = False
                break
            if allMatched: ret.append(m)
        return ret
727804
private static List<PathMatcher> toMatchChain(String path) {
        String[] pieces = path.split(PATH_SEPARATOR);

        List<PathMatcher> matchers = new ArrayList<PathMatcher>();
        for (String piece : pieces) {
            matchers.add((piece.startsWith(":")) ? new GreedyPathMatcher(piece) : new SimplePathMatcher(piece));
        }

        return Collections.unmodifiableList(matchers);
    }
973404
def separate(self):
        '''

        '''
        collections = []
        start = None
        end = None

        for index in self.indexes:
            if start is None:
                start = index
                end = start
                continue

            if index != (end + 1):
                collections.append(
                    Collection(self.head, self.tail, self.padding,
                               indexes=set(range(start, end + 1)))
                )
                start = index

            end = index

        if start is None:
            collections.append(
                Collection(self.head, self.tail, self.padding)
            )
        else:
            collections.append(
                Collection(self.head, self.tail, self.padding,
                           indexes=range(start, end + 1))
            )

        return collections
241517
def split_every(n, iterable):
    """"""
    items = iter(iterable)
    return itertools.takewhile(bool, (list(itertools.islice(items, n)) for _ in itertools.count()))
409335
private void treeWalker(Node node, int level, List<PathQueryMatcher> queryMatchers, List<Node> collector) {
        MatchType matchType = queryMatchers.get(level).match(level, node);
        if(matchType == MatchType.NOT_A_MATCH) {
            // no reason to scan deeper
            //noinspection UnnecessaryReturnStatement
            return;
        } else if(matchType == MatchType.NODE_MATCH) {
            // we have a match
            if(level == queryMatchers.size()-1) {
                // full path match
                collector.add(node);
            } else if(node instanceof Element) {
                // scan deeper
                Element element = (Element) node;
                List<Node> childElements = element.getChildElements();
                for (Node childElement : childElements) {
                    treeWalker(childElement, level+1, queryMatchers, collector);
                }
            }
        } else {
            throw new PathQueryException("Unknown MatchType: " + matchType);
        }
    }
1270400
def _build_matches(matches, uuids, no_filtered, fastmode=False):
    """"""

    result = []

    for m in matches:
        mk = m[0].uuid if not fastmode else m[0]
        subset = [uuids[mk]]

        for id_ in m[1:]:
            uk = id_.uuid if not fastmode else id_
            u = uuids[uk]

            if u not in subset:
                subset.append(u)

        result.append(subset)

    result += no_filtered
    result.sort(key=len, reverse=True)

    sresult = []
    for r in result:
        r.sort(key=lambda id_: id_.uuid)
        sresult.append(r)

    return sresult
239511
private static String matchPathLists(List<String> basePath, List<String> filePath) {
        // start at the beginning of the lists
        // iterate while both lists are equal
        final StringBuilder relativePath = new StringBuilder();
        final ListIterator<String> basePathItr = basePath.listIterator(basePath.size() - 1);
        final ListIterator<String> filePathItr = filePath.listIterator(filePath.size() - 1);
        
        // first eliminate common root elements
        while (basePathItr.hasPrevious() && filePathItr.hasPrevious()) {
            if (!basePathItr.previous().equals(filePathItr.previous())) {
                basePathItr.next();
                filePathItr.next();
                break;
            }
        }

        // for each remaining level in the home path, add a ..
        for (; basePathItr.hasPrevious(); basePathItr.previous()) {
            relativePath.append("..").append(File.separator);
        }

        // for each level in the file path, add the path
        while (filePathItr.hasPrevious()) {
            relativePath.append(filePathItr.previous());
            if (filePathItr.hasPrevious()) {
                relativePath.append(File.separator);
            }
        }

        return relativePath.toString();
    }
9670
public static final <T> List<List<T>> split(List<T> list, Predicate<T> predicate)
    {
        if (list.isEmpty())
        {
            return Collections.EMPTY_LIST;
        }
        List<List<T>> lists = new ArrayList<>();
        boolean b = predicate.test(list.get(0));
        int len = list.size();
        int start = 0;
        for (int ii=1;ii<len;ii++)
        {
            boolean t = predicate.test(list.get(ii));
            if (b != t)
            {
                lists.add(list.subList(start, ii));
                start = ii;
                b = t;
            }
        }
        lists.add(list.subList(start, len));
        return lists;
    }
367659
def fromlist(cls, rnglist, autostep=None):
        """"""
        inst = RangeSet(autostep=autostep)
        inst.updaten(rnglist)
        return inst
177208
def split_subsets(self, train_size:float, valid_size:float, seed=None) -> 'ItemLists':
        ""
        assert 0 < train_size < 1
        assert 0 < valid_size < 1
        assert train_size + valid_size <= 1.
        if seed is not None: np.random.seed(seed)
        n = len(self.items)
        rand_idx = np.random.permutation(range(n))
        train_cut, valid_cut = int(train_size * n), int(valid_size * n)
        return self.split_by_idxs(rand_idx[:train_cut], rand_idx[-valid_cut:])
961391
def split_by_list(self, train, valid):
        ""
        return self._split(self.path, train, valid)
1362751
def _walk_through_splits(self):
        
        def walk(split):
            for c in split:
                if isinstance(c, (HSplit, VSplit)):
                    yield split, c
                    for i in walk(c):
                        yield i

        return walk(self.root)
795187
def split(s):
  """"""
  l = [_split(x) for x in _SPLIT_RE.split(s)]
  return [item for sublist in l for item in sublist]
1341764
def split_input(val, mapper=None):
    '''
    
    '''
    if mapper is None:
        mapper = lambda x: x
    if isinstance(val, list):
        return list(map(mapper, val))
    try:
        return list(map(mapper, [x.strip() for x in val.split(',')]))
    except AttributeError:
        return list(map(mapper, [x.strip() for x in six.text_type(val).split(',')]))
996462
public static WildcardPatternMatcher compile(String patterns) {
		if(patterns == null || patterns.isEmpty()) {
			return matchNone;
		} else {
			List<String> list = StringUtility.splitStringCommaSpace(patterns);
			// Match none shortcut
			if(list.isEmpty()) return matchNone;

			// Parse into a series of individual matchers
			final List<WildcardPatternMatcher> matchers = new ArrayList<>(list.size());
			for(String pattern : list) {
				int end = pattern.length();
				if(end > 0) {
					// Beginning wildcards
					int pos = 0;
					final boolean startsWildcard;
					if(pattern.charAt(0) == '*') {
						startsWildcard = true;
						pos++;
						// Skip consecutive beginning
						while(pos < end && pattern.charAt(pos) == '*') pos++;
						if(pos >= end) {
							// Is any number of '*' only, matchAll shortcut
							return matchAll;
						}
					} else {
						startsWildcard = false;
					}
					// Ending wildcards
					final boolean endsWildcard;
					if(pattern.charAt(end - 1) == '*') {
						endsWildcard = true;
						end--;
						// Skip consecutive ending
						while(end > pos && pattern.charAt(end - 1) == '*') end--;
						assert end > pos;
					} else {
						endsWildcard = false;
					}
					// Split the remaining pattern on any internal '*'
					final List<String> sequences = new ArrayList<>();
					while(pos < end) {
						assert pattern.charAt(pos) != '*';
						int starPos = pattern.indexOf('*', pos + 1);
						if(starPos == -1 || starPos >= end) {
							// Not more '*' found
							sequences.add(pattern.substring(pos, end));
							pos = end;
						} else {
							// Found
							sequences.add(pattern.substring(pos, starPos));
							pos = starPos + 1;
							// Skip consecutive
							while(pos < end && pattern.charAt(pos) == '*') pos++;
						}
					}
					int seqCount = sequences.size();
					assert seqCount >= 1;
					if(seqCount == 1) {
						final String sequence = sequences.get(0);
						if(startsWildcard) {
							if(endsWildcard) {
								// *infix*
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.contains(sequence);
										}
									}
								);
							} else {
								// *suffix
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.endsWith(sequence);
										}
									}
								);
							}
						} else {
							if(endsWildcard) {
								// prefix*
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.startsWith(sequence);
										}
									}
								);
							} else {
								// exact
								matchers.add(
									new WildcardPatternMatcher() {
										@Override
										public boolean isMatch(String paramName) {
											return paramName.equals(sequence);
										}
									}
								);
							}
						}
					} else {
						matchers.add(
							new WildcardPatternMatcher() {
								@Override
								public boolean isMatch(String paramName) {
									int index = 0;
									int indexEnd = sequences.size();
									int pos = 0;
									int end = paramName.length();
									// Handle non-wildcard start
									if(!startsWildcard) {
										String prefix = sequences.get(0);
										if(!paramName.startsWith(prefix)) {
											return false;
										}
										index++;
										pos += prefix.length();
									}
									// Handle non-wildcard end
									if(!endsWildcard) {
										indexEnd--;
										String suffix = sequences.get(indexEnd);
										if(!paramName.endsWith(suffix)) {
											return false;
										}
										end -= suffix.length();
									}
									// Check if overlapping prefix and suffix matches
									if(end < pos) return false;
									// Handle any remaining infixes
									while(index < indexEnd) {
										String sequence = sequences.get(index++);
										int sequenceLen = sequence.length();
										assert sequenceLen > 0;
										int foundAt = paramName.indexOf(sequence, pos);
										if(foundAt == -1 || foundAt > (end - sequenceLen)) {
											return false;
										}
										pos += sequenceLen;
									}
									return true;
								}
							}
						);
					}
				}
			}
			if(matchers.isEmpty()) {
				return matchNone;
			}
			if(matchers.size() == 1) return matchers.get(0);
			return new WildcardPatternMatcher() {
				@Override
				public boolean isMatch(String paramName) {
					for(WildcardPatternMatcher matcher : matchers) {
						if(matcher.isMatch(paramName)) return true;
					}
					return false;
				}
			};
		}
	}
91445
function SingleStarIterator(node, match, all) {
  this.q = node.children.toArray();
  this.m = match;
  this.a = all;
}