Unique characters: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Added a variant which reduces the strings down to a hash of character frequencies)
Line 914: Line 914:
<lang python>'''Unique characters'''
<lang python>'''Unique characters'''


from itertools import chain, groupby
from functools import reduce




# uniques :: [String] -> [Char]
# uniqueChars :: [String] -> [Char]
def uniques(xs):
def uniqueChars(ws):
'''Characters which occur only once
'''Characters which occur only once
across the given list of strings.
across the given list of strings.
'''
'''
return [
return sorted([
h for h, (_, *tail) in
k for (k, v) 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: Line 941:
# main :: IO ()
# main :: IO ()
def main():
def main():
'''Test'''
'''Characters occurring only once
across a list of 3 given strings.
'''
print(
print(
uniques([
uniqueChars([
"133252abcdeeffd",
"133252abcdeeffd",
"a6789798st",
"a6789798st",