Why For Loop Skips the Last element?

Thuruv V wasp52dex at gmail.com
Wed Dec 31 16:25:49 EST 2014


Hi all,

Here's the list. .

inlist = ["Fossil Women's Natalie Stainless Steel Watch Brown (JR1385)",
'Balmer Swiss Made Veyron Mens Watch: Black Band/ Black Dial (62625241)',
'Fortune NYC Ladies Quilted Dial Watch: Brown',
'Jeanne Collection w/ Swarovski Elements Watch: Dark Purple Band
(62623659)',
'Swiss Legend Commander Chronograph: Watch Orange/Black (SL-10067-01-ORS)',
'Debussy Ladies Watch: Brown/Gray/Silver 14070 - 62625292',
'#2 Swiss Legend Commander Chronograph: Green (SL-10067-BB-017)',
'Auguste Jaccard 3 Timezone Watch: Black Band/ Gray & Black Dial (62625184)'
]

My code :
i = 0
while i <= len(inlist):
    if 'watch' in str(inlist[i]).lower() or 'watches' in
str(inlist[i]).lower():
        if 'women' in str(inlist[i]).lower() or 'female' in
str(inlist[i]).lower() or 'ladies' in str(inlist[i]).lower():
            print 'FEMale Watch', inlist.index(i),str(i)
        elif 'men' in str(inlist[i]).lower() or 'male' in
str(inlist[i]).lower() or 'chronograph' in str(inlist[i]).lower():
            print 'Male Watch',inlist.index(i),str(i)
        i = next(inlist)

When on executing python skips the last element('Auguste Jaccard 3 Timezone
Watch: Black Band/ Gray & Black Dial (62625184)') in the list.

But when accessing through 'print inlist[0]' is possible,i.e it shows the
e;lement. but the list skips it. .
Please enlighten me. .
Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150101/fa85a860/attachment.html>


More information about the Python-list mailing list