[Tutor] Lists and While Loops

Emile van Sebille emile at fenx.com
Wed Mar 28 22:15:47 CEST 2012


On 3/28/2012 11:53 AM Ricky Brown said...
> So I have to write a program that reads a message from the user and
> prints a new message

ok --

> 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.

?? doesn't this mean repeat the exact same message?  IOW if the user 
suppies:

This is is a test test

the above rule would resuire you to output exactly the same input I 
think....


>
> What I have thus far looks like this:
>
> message = input("Your message:")

so, "print message" does it...

... but I suspect your requirement isn't accurate.

Emile




> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list