473,503 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: Enumerating ordered expat attributes with tuplets?

On Sep 11, 4:48*pm, Manuel Ebert <maeb...@uos.dewrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Ah, well. Don't know whether it meets your aesthetic standards, but:
*>>my_list = ['tree', 'hug', 'flower', 'hug', 'bear', 'run']
*>>my_list[0:len(a):2]
['tree', 'flower', 'bear']
*>>my_list[1:len(a):2]
['hug', 'hug', 'run']

and hence

*>>zip(my_list[0:len(a):2], my_list[1:len(a):2])
[('tree', 'hug'), ('flower', 'hug'), ('bear', 'run')]

and furthermore

*>>for a, b in zip(my_list[0:len(a):2], my_list[1:len(a):2]):
... * * print a, b
...
tree hug
flower hug
bear run

or the slightly less obfuscated:

*>>for index in range(0, len(my_list), 2):
... * * print my_list[index], my_list[index + 1]
... * *
tree hug
flower hug
bear run
[snip]
I don't know what the "len(a)" is, but the end position defaults to
the end:
>>zip(my_list[0::2], my_list[1::2])
[('tree', 'hug'), ('flower', 'hug'), ('bear', 'run')]
Sep 11 '08 #1
0 846

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

Similar topics

1
1605
by: Ingo Blank | last post by:
Hi, while 95% of my 'psycoed' applications run fine, it throws SIGSEGVs in conjunction with expat. Anybody noticed the same ? Python 2.3.2 (#4, Nov 13 2003, 02:10:49) on linux2 $ uname...
1
1807
by: David | last post by:
Hi, I'm trying to parse an xml file and am a bit confused. I have created my class XmlParser. Also I have 3 other questions. 1-How to the GetAttribute to search for the value of a specific...
4
1866
by: Sridhar | last post by:
HI All, Currently writing a small program and here is my xml file and program. --------------------------------------------------------------------------------- <?xml version="1.0"...
210
10272
by: Christoph Zwerschke | last post by:
This is probably a FAQ, but I dare to ask it nevertheless since I haven't found a satisfying answer yet: Why isn't there an "ordered dictionary" class at least in the standard list? Time and again...
0
1344
by: tvmaly | last post by:
I was trying to find some examples of using expat 2.0 with C++. Specifically I was looking for an example, that if it found a certain start tag, then it would grab the whole string or possibly just...
2
3726
by: dwelch91 | last post by:
Hi, c.l.p.'ers- I am having a problem with the import of xml.parsers.expat that has gotten me completely stumped. I have two programs, one a PyQt program and one a command line (text) program...
10
6743
by: pamelafluente | last post by:
Hi I have a sorted list with several thousands items. In my case, but this is not important, objects are stored only in Keys, Values are all Nothing. Several of the stored objects (might be a...
4
1807
by: davearkley | last post by:
I've recently 'discover' the wonders of custom attributes and reflection. There's one aspect that has stumping me and I've been unable to find samples in the docs or on the web. I have fields in...
6
2622
by: kaens | last post by:
Hey everyone, this may be a stupid question, but I noticed the following and as I'm pretty new to using xml and python, I was wondering if I could get an explanation. Let's say I write a simple...
1
1862
by: vadlapatlahari | last post by:
Hi, I get the following error with Expat while configuring my application server. Can anyone suggest a solution? When i do an ldd, i get the following : $ldd Expat.so Expat.so needs:...
0
7199
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
7076
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...
0
7274
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
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
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...
0
3162
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...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.