Sort an array of strings to groups by patterns
559518
def sort2groups(array, gpat=['_R1','_R2']):
   
   groups = [REGroup(gp) for gp in gpat]
   unmatched = []
   for item in array:
      matched = False
      for m in groups:
         if m.match(item):
            matched = True
            break
      if not matched: unmatched.append(item)
   return [sorted(m.list) for m in groups], sorted(unmatched)
231224
def groupletters(x, _low=lower_function):
    
    return "".join(ichain.from_iterable((_low(y), y) for y in x))
658640
function walk(patterns, cwd) {
	var externals, files, locals;

	if (typeof patterns === 'undefined') {
		return [];
	}

	patterns = (patterns instanceof Array) ? patterns : [patterns];
	cwd = cwd || process.cwd();

	externals = [];
	files = {};
	locals = {};

	each(patterns, function(pattern) {
		var globbed;

		globbed = glob.sync(pattern, {
			cwd: cwd
		});

		globbed.forEach(function(filename) {
			var file;

			file = new File(cwd, filename);
			files[file.path] = file;
		});
	});

	each(_flatten(files), function(file, path) {
		Array.prototype.push.apply(externals, file.external);
		locals[pubname(path, cwd)] = file;
	});

	unique(externals);

	return {
		externals: externals,
		locals: locals
	};
}
165518
function getPatterns() {
        if (isPatternsDirty) {
          patterns.sort(function (a, b) {
            if (a.start.length > b.start.length) {
              return -1;
            }

            if (a.start.length < b.start.length) {
              return 1;
            }

            return 0;
          });

          isPatternsDirty = false;
        }

        return patterns;
      }
196039
public static String[] splitToArray(String str, Pattern separatorPattern, int limit, boolean isTrim, boolean ignoreEmpty){
		return toArray(split(str, separatorPattern, limit, isTrim, ignoreEmpty));
	}
119787
def do_group_by(self, element, decl, pseudo):
        """"""
        sort_css = groupby_css = flags = ''
        if ',' in decl.value:
            if decl.value.count(',') == 2:
                sort_css, groupby_css, flags = \
                        map(serialize, split(decl.value, ','))
            else:
                sort_css, groupby_css = map(serialize, split(decl.value, ','))
        else:
            sort_css = serialize(decl.value)
        if groupby_css.strip() == 'nocase':
            flags = groupby_css
            groupby_css = ''
        sort = css_to_func(sort_css, flags,
                           self.css_namespaces, self.state['lang'])
        groupby = css_to_func(groupby_css, flags,
                              self.css_namespaces, self.state['lang'])
        step = self.state[self.state['current_step']]

        target = self.current_target()
        target.sort = sort
        target.lang = self.state['lang']
        target.isgroup = True
        target.groupby = groupby
        #  Find current target, set its sort/grouping as well
        for pos, action in \
                enumerate(reversed(step['actions'])):
            if action[0] == 'target' and \
                    action[1].tree == element.etree_element:
                action[1].sort = sort
                action[1].isgroup = True
                action[1].groupby = groupby
                break
956073
function filter(patterns) {
  if (typeof patterns === 'function') {
    return patterns;
  }

  return function(str) {
    var arr = ['\\[\\!\\[', '{%', '<%'].concat(patterns || []);
    var re = new RegExp(arr.join('|'));
    return !re.test(str);
  };
}
915646
def most_even_chunk(string, group):
    """"""
    counts = [0] + most_even(len(string), group)
    indices = accumulate(counts)
    slices = window(indices, 2)
    return [string[slice(*one)] for one in slices]
575373
def _array(group_idx, a, size, fill_value, dtype=None):
    """"""
    if fill_value is not None and not (np.isscalar(fill_value) or
                                       len(fill_value) == 0):
        raise ValueError("fill_value must be None, a scalar or an empty "
                         "sequence")
    order_group_idx = np.argsort(group_idx, kind='mergesort')
    counts = np.bincount(group_idx, minlength=size)
    ret = np.split(a[order_group_idx], np.cumsum(counts)[:-1])
    ret = np.asanyarray(ret)
    if fill_value is None or np.isscalar(fill_value):
        _fill_untouched(group_idx, ret, fill_value)
    return ret
1052515
public static Iterable<MatchResult> findMatches(Pattern pattern, CharSequence s) {
		List<MatchResult> results = new ArrayList<MatchResult>();

		for (Matcher m = pattern.matcher(s); m.find();)
			results.add(m.toMatchResult());

		return results;
	}

	/**
	 * Sorts a given HashMap using a custom function
	 * @param m Map of items to sort
	 * @return sorted List of items
	 */
    public static List<Pattern> sortByValue(final HashMap<Pattern,String> m) {
        List<Pattern> keys = new ArrayList<Pattern>();
        keys.addAll(m.keySet());
        Collections.sort(keys, new Comparator<Object>() {
            @SuppressWarnings({ "unchecked", "rawtypes" })
			public int compare(Object o1, Object o2) {
                Object v1 = m.get(o1);
                Object v2 = m.get(o2);
                if (v1 == null) {
                    return (v2 == null) ? 0 : 1;
                } else if (v1 instanceof Comparable) {
                    return ((Comparable) v1).compareTo(v2);
                } else {
                    return 0;
                }
            }
        });
        return keys;
    }
}
1001996
protected function createPatternsForStrings(array $strings) {
        $patterns = [];

        foreach ($strings as $string) {
            $string = preg_quote($string);

            // dist
            $patterns[] = s('#^(%s)$#', $string);
            // dist.
            $patterns[] = s('#^(%s)[._+:-]+#', $string);
            // .dist
            $patterns[] = s('#[._+:-]+(%s)$#', $string);
            // .dist.
            $patterns[] = s('#[._+:-]+(%s)[._+:-]+#', $string);
        }

        return $patterns;
    }
527106
def sort_list(items):
    """"""

    # Track by number of words.
    track = {}

    def by_length(word1, word2):
        return len(word2) - len(word1)

    # Loop through each item.
    for item in items:
        # Count the words.
        cword = utils.word_count(item, all=True)
        if cword not in track:
            track[cword] = []
        track[cword].append(item)

    # Sort them.
    output = []
    for count in sorted(track.keys(), reverse=True):
        sort = sorted(track[count], key=len, reverse=True)
        output.extend(sort)

    return output
426265
def _join_strings(x):
    """"""
    for i in range(len(x)-1):  # Process successive pairs of elements
        if x[i]['t'] == 'Str' and x[i+1]['t'] == 'Str':
            x[i]['c'] += x[i+1]['c']
            del x[i+1]  # In-place deletion of element from list
            return None  # Forces processing to repeat
    return True
618628
def get_sorted_tags(self, pattern):
        
        matcher = re.compile(pattern)
        tags = []
        for tag in self.get_repo().git.tag().split('\n'):
            m = matcher.match(tag)
            if m:
                numbers = []
                for k, v in m.groupdict().items():
                    if k.startswith('cmp'):
                        numbers.append((int(k[3:]), int(v)))
                numbers.sort()

                tags.append((tag, numbers))
        return map(lambda t: t[0], sorted(tags, key=lambda t: t[1], reverse=True))
1155785
def make_pattern_list(patterns):
    """"""
    pattstrs = []
    for desc, patts in patterns:
        # ";," not allowed in descriptions or patterns
        patts = [p.replace(";", "").replace(",", "") for p in patts]
        desc = desc.replace(";", "").replace(",", "")
        pattstrs.append("%s=%s" % (desc, ','.join(patts)))
    return ";".join(pattstrs)
1139151
function arrayOfStrings(a, checkLowerCase) {
    var v = check.array(a) && a.every(check.string);
    if (v && check.bool(checkLowerCase) && checkLowerCase) {
      return a.every(check.lowerCase);
    }
    return v;
  }
694100
public static List<Pattern> getPatternsFromStrings(List<String> strings) {
    List<Pattern> patterns = Lists.newArrayList();
    for (String s : strings) {
      patterns.add(Pattern.compile(s));
    }
    return patterns;
  }