Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,22 @@
|
|||
from itertools import (groupby)
|
||||
|
||||
|
||||
# nubByKey :: (a -> b) -> [a] -> [a]
|
||||
def nubByKey(k, xs):
|
||||
return list(list(v)[0] for _, v in groupby(sorted(xs, key=k), key=k))
|
||||
|
||||
|
||||
xs = [
|
||||
'apple', 'apple',
|
||||
'ampersand', 'aPPLE', 'Apple',
|
||||
'orange', 'ORANGE', 'Orange', 'orange', 'apple'
|
||||
]
|
||||
for k in [
|
||||
id, # default case sensitive uniqueness
|
||||
lambda x: x.lower(), # case-insensitive uniqueness
|
||||
lambda x: x[0], # unique first character (case-sensitive)
|
||||
lambda x: x[0].lower(), # unique first character (case-insensitive)
|
||||
]:
|
||||
print (
|
||||
nubByKey(k, xs)
|
||||
)
|
||||
Loading…
Add table
Add a link
Reference in a new issue