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))
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 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']
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'