[Tutor] Lists and While Loops

Ricky Brown rjbrow2 at gmail.com
Wed Mar 28 20:53:36 CEST 2012


So I have to write a program that reads a message from the user and prints
a new message that contains all the words from the original message but in
the same order without repeating any of them unless they show up more than
once in the original message.

What I have thus far looks like this:

message = input("Your message:")
myList = message.split()
y = random.choice(myList)
z = len(myList)
while z !=0:
    myList.remove(y)
    print(y)

I can't figure out
1) How to remove "y" from the list and continue the loop; when I use
.remove etc. it runs once then give me the error that "y" is not in the
list.

I imagine the answer is quite simple I'm just getting really frustrated
trying to get this done any advice is appreciated.

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120328/9dd454e1/attachment.html>


More information about the Tutor mailing list