2

I'm trying to use the lambda function.

import random
from string import ascii_letters

choice = lambda x: x[int(random()* len(x))]

print(choice("azerty"))

But I get an error :

TypeError: 'module' object is not callable

I'm confused. Can you help me ? Thanks.

1 Answers1

0

Use this. random is a module which contains a function called random. You can use it by doing random.random().

choice = lambda x: x[int(random.random()* len(x))]

If you want you random() directly then use this.

from random import random
choice = lambda x: x[int(random()* len(x))]
Ch3steR
  • 20,090
  • 4
  • 28
  • 58