Permutations of a List

Advanced

Permutations of a List

Welcome to the magical world where you can rearrange items at will! In this challenge, you'll dabble with permutations. Let's call them magic shuffles!

You are asked to create a function called generate_permutations. This function should take a list (an array) of unique items and return all possible permutations of those items.

A permutation is a way to arrange all the elements of a set into some sequence or order. That means if you have a list with 3 items like [1, 2, 3], it's your task to find all possible different orders in which they can appear.

This is a great exercise to understand the concepts of recursion and how to explore all the possibilities of arrangements.

Examples:

# Example 1: Permutations of a simple list result = generate_permutations([1, 2, 3]) # Expected output: # [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]] # Example 2: Permutations of a two-element list result = generate_permutations(["a", "b"]) # Expected output: # [['a', 'b'], ['b', 'a']]

Let's see how creative you can get with your list permutations! Ready, set, code!

Geek
Inputs

Arg 1:

[1,2,3]
Expected Output
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
Actual Output
Permutations of a List [advanced] | Coding for Kids