String Permutations
String Permutations
Hey there, budding coder! Are you ready for a fun and brain-teasing challenge? Imagine you have a magic hat, and inside this hat are letters. Your task is to figure out all the different ways you can arrange these letters. These arrangements are called permutations.
For this challenge, you'll write a function string_permutations that takes a string as its parameter and returns a list of all possible permutations of that string, in alphabetical order.
Here's the twist: permutations are like anagrams, but we want all possible arrangements, not just meaningful words. Each letter can appear only once in each arrangement, and the output list should not contain duplicates.
Examples
-
When you call the function with the input
"abc", it should return all the ways we can rearrange these three letters:string_permutations("abc") # Output: ['abc', 'acb', 'bac', 'bca', 'cab', 'cba'] -
For the string
"aab", note that it contains repeated characters:string_permutations("aab") # Output: ['aab', 'aba', 'baa']
Get ready to unravel the possibilities and reveal the magic of permutations!
Inputs
Arg 1:
"abc"Expected Output
["abc", "acb", "bac", "bca", "cab", "cba"]Actual Output