Re: [Tutor] iterating over less than a full list

2010-09-05 Thread Dave Angel
Bill Allen wrote: Thanks to everyone who replied. Some of the methods presented where some I had thought of, others were new to me. Particularly, I did not realize I could apply a slice to a list. The for x in some_stuff[:value] form worked very well for my purposes. I can also see I need

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Bill Allen
Thanks to everyone who replied. Some of the methods presented where some I had thought of, others were new to me. Particularly, I did not realize I could apply a slice to a list. The for x in some_stuff[:value] form worked very well for my purposes. I can also see I need to look into the ite

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Dave Angel
Bill Allen wrote: Say I have and iterable called some_stuff which is thousands of items in length and I am looping thru it as such: for x in some_stuff etc... However, what if I want only to iterate through only the first ten items of some_stuff, for testing purposes. Is there a concise

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Steven D'Aprano
On Sun, 5 Sep 2010 03:14:24 am Bill Allen wrote: > Say I have and iterable called some_stuff which is thousands of items > in length and I am looping thru it as such: > > for x in some_stuff > etc... > > However, what if I want only to iterate through only the first ten > items of some_stuff,

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Mark Lawrence
On 04/09/2010 18:29, Sander Sweers wrote: On 4 September 2010 19:25, Sander Sweers wrote: for x in some_stuff: if x<= 10: print x else: break Oops, corrected version... count = 0 for x in some_stuff: if count< 10: print x count +=1 else:

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Sander Sweers
On 4 September 2010 19:25, Sander Sweers wrote: > for x in some_stuff: >    if x <= 10: >        print x >    else: >        break Oops, corrected version... count = 0 for x in some_stuff: if count < 10: print x count +=1 else: break Greets Sander ___

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Sander Sweers
On 4 September 2010 19:14, Bill Allen wrote: > Say I have and iterable called some_stuff which is thousands of items in > length and I am looping thru it as such: > > for x in some_stuff > etc... > > However, what if I want only to iterate through only the first ten items of > some_stuff, for

Re: [Tutor] iterating over less than a full list

2010-09-04 Thread Nitin Pawar
if its a dictionary, then I think you will need to use limit if its normal array you can use range(0,10) and access some_stuff[i] On Sat, Sep 4, 2010 at 10:44 PM, Bill Allen wrote: > Say I have and iterable called some_stuff which is thousands of items in > length and I am looping thru it as su

[Tutor] iterating over less than a full list

2010-09-04 Thread Bill Allen
Say I have and iterable called some_stuff which is thousands of items in length and I am looping thru it as such: for x in some_stuff etc... However, what if I want only to iterate through only the first ten items of some_stuff, for testing purposes. Is there a concise way of specifying tha