<br><br><div class="gmail_quote">On Wed, Mar 28, 2012 at 2:53 PM, Ricky Brown <span dir="ltr">&lt;<a href="mailto:rjbrow2@gmail.com">rjbrow2@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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. <div>

<br></div><div>What I have thus far looks like this: </div><div><br></div><div><div>message = input(&quot;Your message:&quot;)</div><div>myList = message.split()</div><div>y = random.choice(myList)</div><div>z = len(myList)</div>

<div>while z !=0:</div><div>    myList.remove(y)</div><div>    print(y)</div><div><br></div><div>I can&#39;t figure out </div><div>1) How to remove &quot;y&quot; from the list and continue the loop; when I use .remove etc. it runs once then give me the error that &quot;y&quot; is not in the list. </div>

<div><br></div><div>I imagine the answer is quite simple I&#39;m just getting really frustrated trying to get this done any advice is appreciated.</div><div><br></div><div>Thanks </div><div>    </div><div>    </div></div>

<br>_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
<br></blockquote></div><br><div><br></div><div>You have two main issues, one, you are not designing the program to do what is specified in the directions, and two, the program you did write has a few things that you need to work on. For the later portion, I&#39;ve provided some commentary below in the body of your code that I have copied over.</div>
<div><br></div><div><div>message = input(&quot;Your message:&quot;)</div><div>myList = message.split()</div><div>y = random.choice(myList)</div><div><br></div><div>#here you have saved some random choice from your list to the variable y.</div>
<div><br></div><div>z = len(myList)</div><div><br></div><div>#Here you save the length of the list to the variable z.</div><div><br></div><div>while z !=0:</div><div>    #the above says, keep doing this loop while z is not equal to 0.</div>
<div>    myList.remove(y)</div><div>    #Here you remove an item from the list, the item stored to the variable y from above.</div><div>    #it&#39;s important to note that this does not change the value of z and this does not change the value of y.</div>
<div>    print(y)</div></div><div>    #y gets printed once</div><div><br></div><div>The loop then goes back up and since z has not changed (and in fact never will change, because you have never told it to change) the while loop runs through another iteration.</div>
<div><br></div><div>However, once myList.remove(y) is evaluated again for the second time it throws an error because y is no longer in the list.</div><div><br></div><div><br></div>