Jump to content

Set consolidation: Difference between revisions

→‎Python: Functional: pylinted for Python 3
(Add link to Range consolidation task)
(→‎Python: Functional: pylinted for Python 3)
Line 1,895:
{{Trans|JavaScript}}
As a fold (catamorphism), using '''union''' in preference to mutation:
{{Works with|Python|3.7}}
<lang python>from functools import (reduce)
<lang python>'''Set consolidation'''
 
<lang python>from functools import (reduce)
 
 
# consolidated :: Ord a => [Set a] -> [Set a]
def consolidated(sets):
'''A consolidated list of sets.'''
def go(xs, s):
if xs:
Line 1,914 ⟶ 1,918:
if __name__ == '__main__':
print(
*list'\n'.join(map(
lambda xs: str(consolidated(map(set, xs))),
[
['ab', 'cd'],
Line 1,922 ⟶ 1,926:
['hik', 'ab', 'cd', 'db', 'fgh']
]
)),
sep='\n'
)</lang>
{{Out}}
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.