Here is a working version of your code.
import random
chars = [1, 6, 7, 8, 5.6, 3]
for k in range(1, len(chars)+1):
thechar = random.choice(chars)
place = chars.index(thechar)
print thechar
chars[place:place+1]=''
When you do the random.choice twice in print random.choice(chars)
and in chars[random.choice(chars)] = ''
, it is picking another random choice from chars
. Instead, set the random.choice
to something so that you can call it later. Even if you had done that, when you set chars[random.choice(chars)] = ''
, it just sets that spot to ''
, it doesn't delete it. So if your random.choice
was 5.6
, the chars
list would just become [1, 6, 7, 8, '', 3]
, not [1, 6, 7, 8, 3]
. To do that, you have to save the place of the char, and do chars[place:place+1]
. And finally, due to the for
syntax, you have to do the len(chars)+1
, so that it only goes to len(chars)
.