python shuffle string
Quick way to shuffle a string.
from random import sample w = "abc" new_w = "".join(sample(w, len(w))) print(new_w)
cba
from random import shuffle w = "abc" shuffle(w) print(w)
TypeErrorTraceback (most recent call last)in 2 3 w = "abc" ----> 4 shuffle(w) 5 print(w) /usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.7/lib/python3.7/random.py in shuffle(self, x, random) 276 # pick an element in x[:i+1] with which to exchange x[i] 277 j = randbelow(i+1) --> 278 x[i], x[j] = x[j], x[i] 279 else: 280 _int = int TypeError: 'str' object does not support item assignment