On Tue, Mar 31, 2015 at 3:37 PM, boB Stepp <robertvst...@gmail.com> wrote: > On Tue, Mar 31, 2015 at 3:28 PM, Zachary Ware > <zachary.ware+py...@gmail.com> wrote: >> On Tue, Mar 31, 2015 at 3:23 PM, boB Stepp <robertvst...@gmail.com> wrote: >>> The following behavior has me stumped: >>> >>> Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit >>> (Intel)] on win32 >>> Type "copyright", "credits" or "license()" for more information. >>>>>> L = ['#ROI:roi_0', '#TXT:text_0', '#1:one^two^three'] >>>>>> for i, item in enumerate(L): >>> subitems = item.split(':') >>> if subitems[0] == '#ROI': >>> print subitems[1] >>> if subitems[0] == '#TXT': >>> print subitems[1] >>> if subitems[0] == '#1' or '#2': >> >> Here's your problem: "#2" is always true. Try "if subitems[0] in >> ['#1', '#2']:" > > Thanks, Zach! About the time your reply arrived I was starting to > realize that my '#1' or '#2' might not be doing what I thought. In the > "Python Pocket Reference" I was just looking at: > > X or Y If X is false then Y; else X. > > I forgot that different languages have different interpretations of "or".
In this case, the differing languages being Python and English :). Also, not that since you aren't using the index for anything, you don't need to use enumerate() to iterate over the list. Just do "for item in L:". Of course, if you actually use the index in the real code that I assume this was cut out of, keep enumerate; it's the right tool for the job. -- Zach _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor