Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

minor issue

Will12483Will12483 Posts: 3Member
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

  • DrostDrost Posts: 24Member
    : 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.