minor issue

I'm trying to make a program that will print out a list of words in a random order, but it should also no repeat any of the words either. This is what I have, can anyone troubleshoot?
Thanks


import random
l1 = [python, apple, cheese, grapes, computer, bread, flower, juice]
print l1
for i in l1:
print i
index = random.randrange(len(l1))
index
print l1[index]
l1 = [python, apple, cheese, grapes, computer, bread, flower, juice]
print l1[index]
#Remove element from list
del l1[index]
print l1

Comments

  • : I'm trying to make a program that will print out a list of words in a random order, but it should also no repeat any of the words either. This is what I have, can anyone troubleshoot?
    : Thanks
    :
    :
    : import random
    : l1 = [python, apple, cheese, grapes, computer, bread, flower, juice]
    : print l1
    : for i in l1:
    : print i
    : index = random.randrange(len(l1))
    : index
    : print l1[index]
    : l1 = [python, apple, cheese, grapes, computer, bread, flower, juice]
    : print l1[index]
    : #Remove element from list
    : del l1[index]
    : print l1
    :

    Just a quickshot early in the morning:

    [code]
    import random
    L = ['abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz']
    random.shuffle(L)
    raw_input(L)
    [/code]

    Of course it only works your way, if you have no repetition in the original list.

    Drost
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion