[Tutor] Unexpected results using enumerate() and .split()
Zachary Ware
zachary.ware+pytut at gmail.com
Tue Mar 31 22:28:39 CEST 2015
On Tue, Mar 31, 2015 at 3:23 PM, boB Stepp <robertvstepp at 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']:"
--
Zach
More information about the Tutor
mailing list