Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One method is to convert the list of lists into a set of tuples, where each tuple represents a sublist. Since sets can only contain unique elements, this will automatically remove any duplicate sublists. Then, the set can be converted back into a list of lists. Here's an example code:

lst = [[1, 2], [3, 4], [1, 2], [5, 6], [3, 4]]
lst_set = set(tuple(sublist) for sublist in lst)
new_lst = [list(tple) for tple in lst_set]
print(new_lst)
# Output: [[1, 2], [3, 4], [5, 6]]

In this example, the original list lst contains two identical sublists: [1, 2] and [3, 4]. After converting the list to a set of tuples and back to a list of lists, the duplicates have been removed, and new_lst only contains [1, 2], [3, 4], and [5, 6].