473,788 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.iterC hildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
Aug 12 '08 #1
5 10703
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.iterC hildren():
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.iterC hildren()
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.iterC hildren():
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.iterC hildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
First solution:

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

Second solution:

from itertools import islice
for x in islice(containe r.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.iterC hildren():
How to skip the first item? It seems that it's a simple question.
Could somebody help me? Thanks.
it = container.iterC hildren()
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
2921
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 works and the event fires except when the user selects the *first* item in the list, which appears to be the default selection, even though the generated HTML code does not have a "selected" property set. Is it possible to cause the...
3
4202
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 dropdownlist to a string var it always returns the first item regardless of what was selected code is simple
2
2862
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, "tblOrders").AddNew() Me.ComboBox1.SelectedIndex = -1 but... how do we deal with the same issue during record navigation? When I move forward or backward onto a null field the combo defaults to the first item on the list again?
5
9905
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 saying that I clicked the first item. Why can't I just select the first item to get an event to fire without having to first select any other item. Thanks for any tips.
0
1349
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 been select by default. So when I click the first items' first letter, it goes to next item starts with same letter. For example, I have
5
3267
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 3D the first item in the ddl to get it to fire for 3D. I have autopostback set to true. I have heard that I need to put a blank item in the ddl, but not sure how I would do this with a dataset.
1
2065
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 put a statement that orders the ListView by a certain column and in a certain order (ascending or descending, it doesn't matter). To do that, I have defined a derived class of the IComparer class (as explained in the Visual Studio MSDN Library)....
10
62841
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
1004
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 combobox that is not the first item, that selected item replaces the first entry in the combobox and I cannot figure out how to get that first item back. I am using VB 2005 Express Any help would be greatly appreciated.
0
9656
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.