Python: Picking an element without replacement
- by wpeters
I would like to slice random letters from a string.
Given
s="howdy"
I would like to pick elements from 's' without replacement but keep the index number.
For example
>>> random.sample(s,len(s))
['w', 'h', 'o', 'd', 'y']
is close to what I want, but I would actually prefer something like
[('w',2), ('h',0), ('o',1), ('d',3), ('y',4)]
with letter-index pairs. This is important because the same letter appears in 's' more than once. ie) "letter" where 't' appears twice but I need to distinguish the first 't' from the 'second'.
Ideally I actually only need to pick letters as I need them but scrambling and calculating all the letters in a list (as shown above) is ok.