this is nested list
[['Dell', 2], ['Dell', 2], ['HP', 1], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Apple', 1], ['Sony', 5], ['Apple', 1]]
Output Should be
[['Dell', 2], ['HP', 1], ['Sony', 5], ['Apple', 1],]
this is nested list
[['Dell', 2], ['Dell', 2], ['HP', 1], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Apple', 1], ['Sony', 5], ['Apple', 1]]
Output Should be
[['Dell', 2], ['HP', 1], ['Sony', 5], ['Apple', 1],]
If the order doesn't matter:
lis = [['Dell', 2], ['Dell', 2], ['HP', 1], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Apple', 1], ['Sony', 5], ['Apple', 1]]
result = list(map(list, set(map(tuple, lis))))
print(result)
Just iterate through you list and add to other list if it is not already added.
data = [['Dell', 2], ['Dell', 2], ['HP', 1], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Apple', 1], ['Sony', 5], ['Apple', 1]]
new_data = []
for i in data:
if i not in new_data:
new_data.append(i)
print(new_data)
# Output [['Dell', 2], ['HP', 1], ['Sony', 5], ['Apple', 1]]
before_remove = [['Dell', 2], ['Dell', 2], ['HP', 1], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Sony', 5], ['Apple', 1], ['Sony', 5], ['Apple', 1]]
remove_duplicates = list(set(tuple(x) for x in before_remove))
if you want the nested items to be lists instead of tuples,
remove_duplicates = [list(y) for y in list(set(tuple(x) for x in before_remove))]