← Back to challenges

Bell Number

PythonHardloopsmath

Instructions

The Bell number is the number of ways a list of n items can be partitioned into non-empty sublists.

Create a function that takes a number n and returns the corresponding Bell number.

Examples

bell(1) ➞ 1
# sample_lst = [1]
# possible_partitions = [[[1]]]

bell(2) ➞ 2
# sample_lst = [1, 2]
# possible_partitions = [[[1, 2]], [[1], [2]]]

bell(3) ➞ 5
# sample_lst = [1, 2, 3]
# possible_partitions = [[[1, 2, 3]], [[1, 2], [3]], [[1], [2, 3]], [[1, 3], [2]], [[1], [2], [3]]]

Notes

N/A

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.