You take a sentence and break it up into words, storing it in a list named "list". Then, for each word in the list, you set list2 to a boolean value of true or false, depending on the result of isupper() and istitle(). Note that the variable "list2" does not refer to a list. It refers to whatever the result of the "or" operation is. Finally, you print out the word from the original, unordered list. You never do anything at all with list2.
At least, that what I think is happening, but I am by no means a Python expert. Here's a suggestion: Try writing out what you want to do in plain English, but formatted sort of like a Python script would be. (This is generally called "pseudocode". It looks like a computer language, but it isn't.) Once you've got that, use it as a framework to write your Python code. Good luck! RobR ________________________________ From: python-list-bounces+rob.richardson=rad-con....@python.org [mailto:python-list-bounces+rob.richardson=rad-con....@python.org] On Behalf Of Cathy James Sent: Wednesday, January 05, 2011 12:57 PM To: python-list@python.org Subject: Help with code-lists and strings Dear all, You folks will probably hear from me more often in the next few months. I hope some of you have time help me on occassion. Actually, a volunteer mentor would be greatly appreciated:) I am learning python and came across an excercise where i need to use lists to strip words from a sentence; starting with those containing one or more uppercase letters, followed by words with lower case letters. When I try, i get words in the order they were written:( I tried if statements, but unsuccessful. This has to be very easy to you experts, but I am clueless ( still rocket science to me) :( #Below is my shot at it: s=input("Write a sentence: ") list=s.strip().split() for word in list: list2 = (word.isupper() or word.istitle()) print (word) else print (word)
-- http://mail.python.org/mailman/listinfo/python-list