21 lines
705 B
Python
21 lines
705 B
Python
import itertools
|
|
|
|
def koordinate(s):
|
|
(start, *dolzina) = s.split("-")
|
|
return (int(start), int(start) + len(dolzina) - 1)
|
|
|
|
def vrstica(s):
|
|
(stev, *ovire) = s.split()
|
|
return list(map(lambda ovira: (*koordinate(ovira), int(stev[1:-1])), ovire))
|
|
|
|
def preberi(s):
|
|
return list(itertools.chain(*map(vrstica, s.splitlines())))
|
|
|
|
def intervali(s):
|
|
return list(map(lambda x: str(x[0]) + "-" * (x[1] - x[0] + 1), s))
|
|
|
|
def zapisi_vrstico(y, xs):
|
|
return " ".join(["(" + str(y) + ")", *intervali(xs)])
|
|
|
|
def zapisi(ovire):
|
|
return "\n".join(map(lambda a: zapisi_vrstico(a[0], map(lambda b: (b[0], b[1]), sorted(a[1]))), itertools.groupby(sorted(ovire, key=lambda x: x[2]), lambda x: x[2]))) |