Trelzevir - 1 year ago 49

Python Question

What is the shortest way to get to two distinct lists,

`a`

`b`

I currently have:

`(a,b)=([randint(0,30)for x in range(10)][randint(0,30)for x in range(10)])`

or

`a=[randint(0,30)for x in range(10)]`

b=[randint(0,30)for x in range(10)]

Using

`a=b=[randint(0,30)for x in range(10)]`

produces two identical lists.

Is there a shorter way to do this?

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

You can use `random.sample`

:

```
from random import sample
r = range(0,30)
a, b = sample(r, 10), sample(r, 10)
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**