cybel
cybel

Reputation: 391

How to remove all items in a list of lists that are not unique?

I'm trying to calculate all unique subgroups of the multiplicative group Z*_7. You can find everything on groups here https://en.wikipedia.org/wiki/Multiplicative_group .

I've tried a lot already. Sets don't really help since they are only removing all duplicated lists but keep one item of the initially not unique lists. I've read quite a few posts here on stackoverflow but none of them really help.

So all possible subgroups of 7 are:

[[1], [1, 5, 7, 11, 13, 17], [1, 7, 13], [1, 5, 7, 11, 13, 17], [1, 7, 13], [1, 17]]

My desired result however should look like this:

[[1], [1, 17]]

Since [1, 7, 13] and [1, 5, 7, 11, 13, 17] are not unique lists in this subgroup I want to have them removed entirely.

Upvotes: 0

Views: 117

Answers (1)

Sebastien D
Sebastien D

Reputation: 4482

Well you can achieve it with the following:

data = [[1], [1, 5, 7, 11, 13, 17], [1, 7, 13], [1, 5, 7, 11, 13, 17], [1, 7, 13], [1, 17]]

print([x for x in data if data.count(x) ==1])

Output:

[[1], [1, 17]]

Upvotes: 2

Related Questions