[Tutor] Unexpected results using enumerate() and .split()

boB Stepp robertvstepp at gmail.com
Tue Mar 31 22:47:09 CEST 2015


On Tue, Mar 31, 2015 at 3:32 PM, Dave Angel <davea at davea.name> wrote:
> On 03/31/2015 04:23 PM, boB Stepp 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':
>
>
> I think what you meant here was:
>            if subitems[0] == "#1" or subitems[0] == "#2":
>
>>                  print subitems[1]
>
>
> Study the first expression and see if you can figure out what the difference
> is.  If it's not clear, then make a simpler program just to test a compound
> if, and we'll all talk about it.

Yeah, your version evaluates to "False or False", which is what I
wanted, but my version didn't.

>> BTW, I copied and pasted the above into my Gmail window, but it
>> removed the indentation that was present in the interpreter. I added
>> spaces manually to get it appear as it did in the interpreter. Anyone
>> know why Gmail does that to my copy and paste?
>>
>
> Buggy, I guess.  Why not use a program like Thunderbird, which is free and
> available on most PC operating systems?
>
> (Unfortunately, it's not on Android)

This is on my TODO list! I had started an earlier thread looking for a
Gmail replacement if you recall. I just haven't gotten riled enough by
Gmail to make the switch, but I am oh, so close!


-- 
boB


More information about the Tutor mailing list