Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

Permutations using Python

Project Status: Active – The project has reached a stable, usable state and is being actively developed.

One simple program using Python for applying strings and integer permutations.
The following gist offers a program scaled in four subsets:

  • apply permutations on strings, refer to
  • apply permutations on integers, refer to
  • apply permutations on both integers and strings in a single program, refer to
  • use case: apply permutations on a card game, refer to

Getting Started

This Python program built in four lines helps you avoid the use of an extented code for applying permutations on numeric data. The below instructions will help you run this Python program on your local machine for development and testing purposes, as well as in third party sites hosted in the cloud.

  • (#) and (''') are used to comment the following gist.


I am using Jupyter Notebook on localhost (Ubuntu 18.04 bionic).
Make sure to have Jupyter Notebook installed on your operating system or launch it on remote servers (see Tips).


If you are not using Linux/Unix and still want to try this simple Python program:

Basic commands in Jupyter Notebook

  • Note that in Jupyter you add new lines by typing "b" from your keyboard whilst the notebook is opened.
  • Avoid runing the entire code in a single cell in order to understand the steps.
  • Use "ctrl + enter" to execute each line if you want to get the output.
  • Use "dd" outside a cell to delete it.
  • Running the last cell should execute the permutations as program output.

Whilst your Jupyter Notebook is open... Use this line of code in your first cell

from itertools import permutations

This loads requested package
and library in your notebook

Use this line of code in your second cell

perm = permutations([3, 6, 9])

This returns no result until
the last cell is ran

Use this line of code in your third cell

for (i) in list(perm): 
print (i)

This completes the program, showing permutations
of numbers 3,6,9 as output.

Running the tests

  • I used Ubuntu (18.04 bionic) to launch Jupyter Notebook on localhost.
  • Localhost instantiates while using $ jupyter notebook in the terminal.
  • Check if Jupyter is correctly installed: $ jupyter --version

Built With

  • Jupyter - An open source software for creating notebooks
  • Itertools - Functions creating iterators for efficient looping
  • Math - Mathematical functions defined by the C standar


I used no vesioning system for this gist, which repos status is flagged as concept because it is intended to be a demo or POC (proof-of-concept).


  • Isaac Arnault - Suggesting a minified code from Initial work redspider


All public gists
Copyright 2018, Isaac Arnault
MIT License,

Use case - Applying a factorial n function in a card game

Extended application of the above program. Permutations are great for finding number of ways an array of integers can be sorted. Let's imagine that that we have a standard 52-card deck and we wish to find the number of permutations of four aces while shuffling the cards. We may need to add a function to our code and to use another package and libraby. Check for more info.


Simple permutations using Python - See original gist ⇢








No releases published


No packages published