[Tutor] for: how to skip items
Mark Lawrence
breamoreboy at yahoo.co.uk
Mon Feb 17 17:39:23 CET 2014
On 17/02/2014 16:17, Gabriele Brambilla wrote:
> Doesn't exist a way in Python to do like in C
>
> for i=0, i<100, i=i+10
>
> ? without creating a list of index?
>
> Gabriele
>
>
> 2014-02-17 11:15 GMT-05:00 David Palao <dpalao.python at gmail.com
> <mailto:dpalao.python at gmail.com>>:
>
> Hi Gabriele,
> Without knowing the details of what you are trying, I guess you could
> be interested in looking at how to define your own iterators.
>
> Regards
>
> 2014-02-17 17:05 GMT+01:00 Gabriele Brambilla
> <gb.gabrielebrambilla at gmail.com
> <mailto:gb.gabrielebrambilla at gmail.com>>:
> > Hi,
> >
> > I'm wondering how I can (if I can) make a for loop in which I
> don't use all
> > the elements.
> >
> > for example
> >
> > a100 = list(range(100))
> >
> > for a in a100:
> > print(a)
> >
> > it print out to me all the numbers from 0 to 99
> > But if I want to display only the numbers 0, 9, 19, 29, 39,
> ...(one every 10
> > elements) how can I do it WITHOUT defining a new list (my real
> case is not
> > so simple) and WITHOUT building a list of indexes?
> >
> > thank you
> >
> > Gabriele
> >
Please don't top post on this list.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com
More information about the Tutor
mailing list