Jump to content

Unique characters: Difference between revisions

→‎{{header|Python}}: Added a variant which reduces the strings down to a hash of character frequencies
(→‎{{header|Python}}: Added a variant which reduces the strings down to a hash of character frequencies)
Line 914:
<lang python>'''Unique characters'''
 
from itertoolsfunctools import chain, groupbyreduce
 
 
# uniquesuniqueChars :: [String] -> [Char]
def uniquesuniqueChars(xsws):
'''Characters which occur only once
across the given list of strings.
'''
return sorted([
hk for h, (_k, *tailv) in reduce(
lambda dct, w: reduce(
groupby(sorted(chain(*xs)))
if not tail lambda a, c: dict(a, **{
c: 1 + a[c] if c in a else 1
]
}),
w,
dct
),
ws,
{}
).items()
if 1 == v
])
 
 
Line 932 ⟶ 941:
# main :: IO ()
def main():
'''Test'''
'''Characters occurring only once
across a list of 3 given strings.
'''
print(
uniquesuniqueChars([
"133252abcdeeffd",
"a6789798st",
9,655

edits

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