builtin_function_or_method' object has no attribute shuffle

Viewed 7991

Hi I am trying to define a function that returns a shuffled list l1 without changing the original list l using the method random.shuffle but I got this error message:

builtin_function_or_method object has no attribute shuffle

import random
def shuffle_list(l):
  l1=random.shuffle(l)
  return(l1)
4 Answers
from random import shuffle
def shuffle_list(l):
  def shuffle_list(l):
    shuffle(l)
    return l

Import shuffle directly and return l and don't save it into any variable because l1 = shuffle(l) will return None

I know this is coming late.

Replace all instances of random.shuffle() with shuffle() after changing the import random with from random import shuffle.

Related