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))
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 "", line 1, in
TypeError: unhashable type: 'list'
Comment
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))
Parent comment
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 "", line 1, in
TypeError: unhashable type: 'list'