Range consolidation: Difference between revisions

→‎Functional Python: Added a couple of comments to the `consolidated` function.
(→‎{{header|Python}}: Added a 'Procedural' peer to the 'Functional' heading)
(→‎Functional Python: Added a couple of comments to the `consolidated` function.)
Line 480:
 
def go(abetc, xy):
'''A copy of the accumulator abetc,
with its head range ab either:
1. x,replaced yby = xyor
2. merged with
the next range xy, or
with xy simply prepended.'''
if abetc:
a, b = abetc[0]
x, y = xy
etc = abetc[1:]
return [xy] + etc ifx, y >= b else (xy
return [(x, b)xy] + etc if y >= ab else ( # ab replaced.
[(x, b)] + etc if y >= a else ( # [xy] + abetcab merged.
[xy] + abetc # xy simply prepended.
)
)
9,655

edits