[Tutor] for: how to skip items

Gabriele Brambilla gb.gabrielebrambilla at gmail.com
Mon Feb 17 17:15:18 CET 2014


Excuse me for the bad english:
not "a random float numbers" but "random float numbers"

Gabriele


2014-02-17 11:13 GMT-05:00 Gabriele Brambilla <
gb.gabrielebrambilla at gmail.com>:

> No sorry,
>
> it's because my problem is not so simple:
> imagine that in a100 contains not integer sorted in a good way but a
> random float numbers.
> How could I display only one item every 10?
>
> thanks
>
> Gabriele
>
>
> 2014-02-17 11:08 GMT-05:00 Oscar Benjamin <oscar.j.benjamin at gmail.com>:
>
> On 17 February 2014 16:05, Gabriele Brambilla
>> <gb.gabrielebrambilla at gmail.com> wrote:
>> > 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?
>>
>> for a in a100:
>>     if a % 10 == 9:
>>         print(a)
>>
>> Alternatively:
>>
>> for a in a100:
>>     if a % 10 == 9:
>>         continue
>>     print(a)
>>
>>
>> Oscar
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140217/7800ca6e/attachment.html>


More information about the Tutor mailing list