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 |
from functools import reduce |
||
# |
# uniqueChars :: [String] -> [Char] |
||
def |
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([ |
||
k for (k, v) in reduce( |
|||
lambda dct, w: reduce( |
|||
groupby(sorted(chain(*xs))) |
|||
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(): |
||
⚫ | |||
'''Characters occurring only once |
|||
across a list of 3 given strings. |
|||
⚫ | |||
print( |
print( |
||
uniqueChars([ |
|||
"133252abcdeeffd", |
"133252abcdeeffd", |
||
"a6789798st", |
"a6789798st", |