<br><br><div class="gmail_quote">On Thu, Jan 29, 2009 at 6:11 AM, garywood <span dir="ltr"><<a href="mailto:pythonsky@sky.com">pythonsky@sky.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">






<div bgcolor="#ffffff">
<div><font face="Arial" size="2">I had a task in a book to pick 5 items from a list 
of 26 ensuring the items are not repeated</font></div>
<div><font face="Arial" size="2"></font> </div>
</div></blockquote></div><br>If the list is unique of 26 elements is guaranteed to be unique, simply:<br><br>   >>> import random<br>   >>> random.sample(list, 5)<br>    ['g', 'y', 'i', 'n', 'x']<br>
<br>If the list isn't unique:<br><br>    >>> import random<br>    >>> random.sample(set(list), 5)<br>    ['r', 'e', 'b', 'k', 'i']<br><br>If you want to combine them all into a single word as you do in your example:<br>
<br>    >>> import random<br>    >>> ''.join(random.sample(set(list), 5))<br>    'wmhsq'<br><br>--Stephen<br>