Geek Culture
Published in

Geek Culture

Cartesian products in Python

Made easy with itertools

The itertools.product function returns the Cartesian product of two or more iterables.

What is the Cartesian product?

Suppose we have two sets of values, for example:

  • a is the set of values (1, 2, 3).
  • b is the set of values ("a", "b", "c", "d").

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Martin McBride

Martin McBride

247 Followers

Freelance software consultant, developer, technical author. Java, Python. martinmcbride.org