-5

In python I want to know how to get random letter from string.

eg.

randomize("HELLO")
returns "L"
Dan Smith
  • 3
  • 1

1 Answers1

-1
return (random.choice(string))
michael_b
  • 124
  • 7
  • Wow that was easy. Thanks! – Dan Smith Jun 05 '17 at 08:15
  • Strings are sequences, there is **no need** to turn them into a list first, `random.choice(string)` works as is. And the latter is trivially done with `list(string)`, no need to write an explicit loop. And `return` is a statement, not a function, just use `return random.choice(string)`. – Martijn Pieters Jun 05 '17 at 08:16