Inplace shuffle function returns none

John Gordon gordon at panix.com
Tue Oct 18 10:52:25 EDT 2016


In <e1d9a80e-6c62-49ba-b946-695150a0de18 at googlegroups.com> Sayth Renshaw <flebber.crue at gmail.com> writes:

> If shuffle is an "in place" function and returns none how do i obtain
> the values from it.

The values are still in the original object -- variable "a" in your example.

> 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?

    a = [1,2,3,4,5]
    shuffle(a)
    print(a[:3])

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list