tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
11
Task/Range-expansion/Python/range-expansion-1.py
Normal file
11
Task/Range-expansion/Python/range-expansion-1.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
def rangeexpand(txt):
|
||||
lst = []
|
||||
for r in txt.split(','):
|
||||
if '-' in r[1:]:
|
||||
r0, r1 = r[1:].split('-', 1)
|
||||
lst += range(int(r[0] + r0), int(r1) + 1)
|
||||
else:
|
||||
lst.append(int(r))
|
||||
return lst
|
||||
|
||||
print(rangeexpand('-6,-3--1,3-5,7-11,14,15,17-20'))
|
||||
11
Task/Range-expansion/Python/range-expansion-2.py
Normal file
11
Task/Range-expansion/Python/range-expansion-2.py
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import re
|
||||
|
||||
def rangeexpand(txt):
|
||||
lst = []
|
||||
for rng in txt.split(','):
|
||||
start,end = re.match('^(-?\d+)(?:-(-?\d+))?$', rng).groups()
|
||||
if end:
|
||||
lst.extend(xrange(int(start),int(end)+1))
|
||||
else:
|
||||
lst.append(int(start))
|
||||
return lst
|
||||
Loading…
Add table
Add a link
Reference in a new issue