Skip to main content
add code.
Source Link
AsukaMinato
  • 10.4k
  • 1
  • 17
  • 44
n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &

As the comment said

Tuples[vals, {n}] // DeleteDuplicatesBy[Sort]

Also works, more clear.

Some explanations:

The key is: you "sort" the list to see whether they are duplicate.

So I use Sort to be DeleteDuplicatesBy's condition.

n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &

Some explanations:

The key is: you "sort" the list to see whether they are duplicate.

So I use Sort to be DeleteDuplicatesBy's condition.

n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &

As the comment said

Tuples[vals, {n}] // DeleteDuplicatesBy[Sort]

Also works, more clear.

Some explanations:

The key is: you "sort" the list to see whether they are duplicate.

So I use Sort to be DeleteDuplicatesBy's condition.

add explanations
Source Link
AsukaMinato
  • 10.4k
  • 1
  • 17
  • 44
n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &

Some explanations:

The key is: you "sort" the list to see whether they are duplicate.

So I use Sort to be DeleteDuplicatesBy's condition.

n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &
n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &

Some explanations:

The key is: you "sort" the list to see whether they are duplicate.

So I use Sort to be DeleteDuplicatesBy's condition.

Source Link
AsukaMinato
  • 10.4k
  • 1
  • 17
  • 44

n = 2;
vals = {0, 1};
Tuples[vals, {n}] // DeleteDuplicatesBy[#, Sort] &