Question: I have a list of lists like the following, and the number and length of sublists can be variable:

```
test = [[1, 5, 4, 3, 5, 2], [4, 2], [5, 2, 4, 3, 5], [5, 3, 1]]

```

I want to downsample all sublists to the length of the shortest sublist - this case 2. That means I want to randomly select 2 elements from all sublists as an output.

For a much larger list of around 100 sublists, each greater than 100000 items, what would the most efficient way be?

Answer: 
Using only the standard library:

```
import random

test = [[1, 5, 4, 3, 5, 2], [4, 2], [5, 2, 4, 3, 5], [5, 3, 1]]

min_size = float("inf")

for sublist in test:
    length = len(sublist)
    if length < min_size:
        min_size = length

new_list = [random.sample(sublist, min_size) for sublist in test]

# [[5, 4], [2, 4], [5, 3], [1, 5]]

```
Short and sweet one-liner using list comprehension:

```
from random import sample

[sample(l, len(min(test, key=len))) for l in test]

```