Back to Python

Python is quite a powerful language! Let's find out how by looking at an interesting example proposed by Tucker Balch.

We'll cover the following

You’ve almost reached the end of the course and, hopefully, you’ve learned that NumPy is a very versatile and powerful library. However in the meantime, remember that Python is also quite a powerful language. In fact, in some specific cases, it might be more powerful than NumPy.

Allocations

Let’s consider, for example, an interesting exercise that has been proposed by Tucker Balch in his Computational Investing course. The exercise is written as:

Write the most succinct code possible to compute all “legal” allocations to 4 stocks such that the allocations are in 1.0 chunks, and the allocations sum to 10.0.

Yaser Martinez collected the different answers from the community and the proposed solutions yield surprising results. But let’s start with the most obvious Python solution:

Get hands-on with 1200+ tech skills courses.