Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Functional Python Programming
  • Toc
  • feedback
Functional Python Programming

Functional Python Programming

By : Steven F. Lott
4 (9)
close
Functional Python Programming

Functional Python Programming

4 (9)
By: Steven F. Lott

Overview of this book

This book is for developers who want to use Python to write programs that lean heavily on functional programming design patterns. You should be comfortable with Python programming, but no knowledge of functional programming paradigms is needed.
Table of Contents (18 chapters)
close
17
Index

Generating all combinations


The itertools module also supports computing all combinations of a set of values. When looking at combinations, the order doesn't matter, so there are far fewer combinations than permutations. The number of combinations is often stated as . This is the number of ways that we can take combinations of r things at a time from a universe of p items overall.

For example, there are 2,598,960 5-card poker hands. We can actually enumerate all 2 million hands by executing the following command:

hands = list(combinations(tuple(product(range(13), '♠♥♦♣')), 5))

More practically, we have a dataset with a number of variables. A common exploratory technique is to determine the correlation among all pairs of variables in a set of data. If there are v variables, then we will enumerate all variables that must be compared by executing the following command:

combinations(range(v), 2)

Let's get some sample data from http://www.tylervigen.com to show how this will work. We'll pick...

bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete