Inplace shuffle function returns none

Chris Angelico rosuav at gmail.com
Tue Oct 18 10:52:12 EDT 2016


On Wed, Oct 19, 2016 at 1:48 AM, Sayth Renshaw <flebber.crue at gmail.com> wrote:
> If shuffle is an "in place" function and returns none how do i obtain the values from it.
>
> from random import shuffle
>
> a = [1,2,3,4,5]
> b = shuffle(a)
> print(b[:3])
>
> For example here i just want to slice the first 3 numbers which should be shuffled. However you can't slice a noneType object that b becomes.
>
> So how do i get shuffle to give me my numbers?
>

In place means that it changes the list. Try print(a) after the shuffle.

ChrisA



More information about the Python-list mailing list