Shuffle and sample

From @Raymond Hettinger we get this tip

#python tip: random.shuffle() is an in-place operation that operates on any mutable sequence. To shuffle in-line or to work from an immutable sequence, use random.sample() instead: >>> s = ‘hello world’ >>> ”.join(random.sample(s, k=len(s))) ‘lld erlohwo’

>>> s = 'hello world'
>>> ''.join(random.sample(s, k=len(s)))
'lld erlohwo'

 

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.