Trelzevir - 9 months ago 33

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?

Answer Source

You can use `random.sample`

:

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