4
$\begingroup$

Say I have a list of strings like

slist={"apple","123","Car"}

What I want is a list of all permutations of slist. The result should be something like that

{"apple","123","Car","apple123","appleCar","apple123Car","Carapple123",...}

The reason for this is that I want to create a dictionary for password recovery.

$\endgroup$
2
  • $\begingroup$ Please try Permutations[slist] $\endgroup$ Commented Nov 2, 2015 at 12:03
  • 1
    $\begingroup$ or Permutations[slist, All]. $\endgroup$
    – Kuba
    Commented Nov 2, 2015 at 12:03

1 Answer 1

7
$\begingroup$
StringJoin /@ Rest @ Permutations[slist, Length @ slist]

{"apple", "123", "Car", "apple123", "appleCar", "123apple", "123Car", "Carapple", "Car123", "apple123Car", "appleCar123", "123appleCar", "123Carapple", "Carapple123", "Car123apple"}

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.