Comment

eseprimo

Did anyone address the issues with non hashable types? Note that sets and non hashable types don't go well together---which renders useless most of the functions above, except when dealing with trivial data. For example,

>>> alist=['a',[1,3,4],[3,3,3],[2,'b'],'a']
>>> set(alist)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'

Replies

Anonymous

Not that hard. Some of the ordering is changed but that could be understandable since we are removing dups.

tp = lambda x: str(type(x)).split("'")[1].split("'")[0].replace("'",'')
alist=['a',[1,3,4],[3,3,3],[2,'b'],'a']
blist = [ i if tp(i) != 'list' else [ j for j in set(i) ] for i in alist ]
print("Alist: {0}\nBList: {1}".format(alist,blist))

Alist: ['a', [1, 3, 4], [3, 3, 3], [2, 'b'], 'a']
BList: ['a', [3, 1, 4], [3], ['b', 2], 'a']

Anonymous

Not too hard. Bit ugly but working.

tp = lambda x: str(type(x)).split("'")[1].split("'")[0].replace("'",'')
alist=['a',[1,3,4],[3,3,3],[2,'b'],'a']
blist = [ i if tp(i) != 'list' else [ j for j in set(i) ] for i in alist ]
clist = list([ i for i in set( [ i if tp(i) != 'list' else '!None' for i in blist ] ) ])[:-1] +[ i for i in blist if tp(i)=='list' ]
print("Alist: {0}\nBList: {1}\nClist: {2}".format(alist,blist, clist))