# Unique list with sub array in subarray

hi all,
i have a list with subarray. each subarray have subarrays

array = [ [[1,2],[2,3],[3,4]], [[5,6],[6,7],[7,8]], [[1,2],[2,3],[3,4]],…]
as shown sub array 1 is equal to sub array 3

the problem is i have array of many many subarrays and i would remove duplicate subarrays quickly

can someone help me?

Convert each subarray into a tuple. Then put those tuples into a set (or a dictionary if you need to remember their original position/order), and you can easily see whether there’s any other that’s equal to it.

Many thanks. Have you example with dictionary?

Something like this:

``````array = [ ((1,2),(2,3),(3,4)), ((5,6),(6,7),(7,8)), ((1,2),(2,3),(3,4)) ]
map = {}
for pos, vector in enumerate(array):
if vector in map:
# Handle duplicates any way you choose.
pass # Simplest option: Keep the first one
else:
map[vector] = pos
array = list(map) # Keep just the ones you care about
``````

There are other ways of handling duplicates, including keeping the last, remembering both/all positions, etc. It’s up to you how to do that.

Note that it’s way way easier if you don’t care about order at all:

``````array = list(set(array))
``````

Is `[[1, 2], [2, 3]]` is considered equal to `[[2, 3], [1, 2]]` or `[[1, 2], [2, 3]]` is considered equal to `[[2, 1], [2, 3]]`?