Creating a function for permutations
Permutations are the number of different combinations you can make when order matters. Permutations are a statistical tool data scientists, and data analysts use from time to time, and it is an important skill to know. To make a permutation function, you will need the itertools library.
To start, import the itertools library.
Next, let’s create a function. I’m going to name my function ‘possibilities.’ Your function can be any name, but you will see ‘possibilities’ as my function in this example.
The function will take one argument, n.
Within the function, I am naming the variable result to contain the number of permutations from any given argument, n. itertools’ built-in permutations will handle the rest.
We want our function to return the length of the list.
In one cell, the function looks like this:
Now we can try out our function.
From the lollipop entry, we see there are 1680 different permutations.