Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: Tools/AutoSheriff/string_helpers.py

Issue 398823008: WIP: Add auto-sheriff.appspot.com code to Blink Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import itertools
6
7 # http://stackoverflow.com/questions/9470611/how-to-do-an-inverse-range-i-e-crea te-a-compact-range-based-on-a-set-of-numb/9471386#9471386
8 def re_range(lst):
9 def sub(x):
10 return x[1] - x[0]
11
12 ranges = []
13 for k, iterable in itertools.groupby(enumerate(sorted(lst)), sub):
14 rng = list(iterable)
15 if len(rng) == 1:
16 s = str(rng[0][1])
17 else:
18 s = "%s-%s" % (rng[0][1], rng[-1][1])
19 ranges.append(s)
20 return ', '.join(ranges)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698