473,387 Members | 3,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to iterate a sequence, with skipping the first item?

ray
A container object provides a method that returns an iterator object.
I need to iterate the sequence with that iterator, but need to skip
the first item. I can only iterate the whole sequence with:
for x in container.iterChildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
Aug 12 '08 #1
5 10674
On Aug 12, 4:51*pm, ray <hanl...@gmail.comwrote:
A container object provides a method that returns an iterator object.
I need to iterate the sequence with that iterator, but need to skip
the first item. I can only iterate the whole sequence with:
for x in container.iterChildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
Does the for loop -have- to contain the reference to iterChildren? If
you can modify that, you can always manually step past the first item:

children = container.iterChildren()
children.next()
for x in children: ...
Aug 12 '08 #2
i = iter(container.iterChildren())
i.next()
for x in i:
...

On Tue, Aug 12, 2008 at 2:51 AM, ray <ha*****@gmail.comwrote:
A container object provides a method that returns an iterator object.
I need to iterate the sequence with that iterator, but need to skip
the first item. I can only iterate the whole sequence with:
for x in container.iterChildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://ironfroggy-code.blogspot.com/
Aug 12 '08 #3
ray <ha*****@gmail.comwrites:
for x in container.iterChildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
First solution:

c = container.iterChildren()
c.next() # skip first item
for x in c: ...

Second solution:

from itertools import islice
for x in islice(container.iterChildren(), 1, None): ...

I like the second solution better but it's a matter of preference.
Aug 12 '08 #4
En Tue, 12 Aug 2008 03:51:17 -0300, ray <ha*****@gmail.comescribi�:
A container object provides a method that returns an iterator object.
I need to iterate the sequence with that iterator, but need to skip
the first item. I can only iterate the whole sequence with:
for x in container.iterChildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
it = container.iterChildren()
it.next() # consume first item
for x in it:
# process remaining items

--
Gabriel Genellina

Aug 12 '08 #5
ray
Thanks you guys. Now I understand the -for- loop mechanism.
Aug 12 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Timo | last post by:
I am trying to use the DropDownList_SelectedIndexChanged event on a dropdown which is dynamically populated with different values at runtime, depending on what the user has been doing. The dropdown...
3
by: Siamak Zahedi | last post by:
Hi, weird problem I'm having cant seem to figure out what is going on. I have a dropdownlist that gets populated from db and a button that causes a post back when I assign the value of the...
2
by: Nate | last post by:
I have used the feedback on this issue to remedy my comboboxes showing the first item on the list when a new record is added to the binding context --- Me.BindingContext(dsOrders,...
5
by: glenn | last post by:
Hi folks, If I want to select the first item in a DropDownList, I need to first select any item other than the first item and then next I select the first item which will then fire an event...
0
by: Ryan Liu | last post by:
In a listview, I found it is pretty nice I can type a letter or more letter quickly to select the NEXT item which begin with that letter(s). But seems the first row, even not high lighted, always...
5
by: Cindy H | last post by:
Hi I have a ddl that I have populated with a dataset. I have 2 items in the ddl. The first one is '3D' and the second one is 'Spot'. I have to select Spot - the second item in the ddl and then...
1
by: polocar | last post by:
Hi, I'm using Visual C# 2005 (part of Visual Studio 2005 Professional Edition), and I have the following problem: I populate a ListView object with several items, and at the end of this process I...
10
by: Frank Rizzo | last post by:
How do I get the first item that was added to the Dictionary object. I've tried myDictionary, but it's not supported? Regards
0
by: uspazn | last post by:
Hello all, I am a newbie and this is my problem. I have a program that uses a simple access database. Seperate tables in the database fill several comboboxes. When the user selects an item in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.