0

How can I display all the permutations in a string or any other iterable in the most simplest way for a beginner...

def permutations(iterable):
       #code here

Ex. Permutations("abc")

Output: "abc","acb","bac","bca","cba","cab"

6
  • 2
    Use recursion Commented May 25, 2020 at 19:05
  • Select each of the input's elements as the start, then use recursion to create permutations of the rest. Commented May 25, 2020 at 19:05
  • 1
    There's some "roughly equivalent" code in the itertools documentation that might help. The Wikipedia article on the subject also describes some algorithms. Commented May 25, 2020 at 19:18
  • This answers your question. stackoverflow.com/a/13109403/7698734 Commented May 25, 2020 at 19:27
  • Does this answer your question? Python recursion permutations Commented May 25, 2020 at 19:44

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.