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.

2
  • 1
    what do you expect random() to do? Commented Feb 18, 2020 at 20:26
  • 1
    In general, lambda expressions are not meant to be assigned to variables. You should use def for that Commented Feb 18, 2020 at 20:47

1 Answer 1

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))]
Sign up to request clarification or add additional context in comments.

Comments