In order to use random.choice()
, I have to convert my string to a list:
>>> x = "hello"
>>> y = list(x)
>>> y
['h', 'e', 'l', 'l', 'o']
But trying to do that in reverse yields a string that actually looks like ['h', 'e', 'l', 'l', 'o']
instead of just hello
. Doing this repeatedly causes an infinite loop that produces strings which look like this:
"'", '"', ',', ' ', "'", ',', "'", ',', ' ', "'", ' ', "'", ',', ' ', "'", '"', "'", ',', ' ', '"', "'", '"', ',', ' ', "'", '"', "'", ',', ' ', "'", ',', "'", ',', ' ', "'", ' ', "'", ',', ' ', '"', "'", '"', ',', ' ', "'", ',', "'", ',', ' ', '"', "'", '"', ',', ' ', "'", ',', "'", ',', ' ', "'", ' ', "'", ',', ' '
And so on.
So, how can I convert the list back into a string:
>>> x = ['x', 'y', 'z']
>>> y = something(x)
>>> y
'xyz'