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

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Apr 1 01:19:16 CEST 2015


On 31/03/2015 21:49, boB Stepp wrote:
> On Tue, Mar 31, 2015 at 3:42 PM, Zachary Ware
> <zachary.ware+pytut at gmail.com> wrote:
>
>> 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.
>
> Yeah, I simplified my actual code into the smallest snippet that I
> could reproduce my problem in. My actual code need the index.
>

Using an index is perhaps the traditional way of doing things but there 
are other options.  As an example you might like to see the pairwise 
function here http://pythonhosted.org//more-itertools/api.html with the 
code available on pypi if you'd like to play.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list