Simple questions on use of objects (probably faq)

Matt Hammond matt.hammond at rd.bbc.co.uk
Wed Mar 8 06:49:24 EST 2006


On Wed, 08 Mar 2006 11:29:29 -0000, Steven D'Aprano  
<steve at REMOVETHIScyber.com.au> wrote:

> On Wed, 08 Mar 2006 11:00:09 +0000, Matt Hammond wrote:
>
>>> 4: Can I avoid the dummy counter i in the for loop and do something
>>> like:
>>> yz=[y[:-1].x-y[1:].x]
>>
>> yz = [e.x for e in y]
>> yz.reverse()
>
> I don't think that's what the O.P. actually wants. He seems to have
> misused slicing syntax as some sort of weird replacement for a for loop.
>
> Of course, I could be wrong.

Hmmm, rereading, I think you're right ... and I think I'm confused too :-)

Attempt #2:

     yz = [ (y1.x - y2.x) for (y1,y2) in zip(y[:-1], y[1:]) ]

Frankly, a for loop with an index would probably be easier to read :)



Matt
-- 

| Matt Hammond
| R&D Engineer, BBC Research & Development, Tadworth, Surrey, UK.
| http://kamaelia.sf.net/
| http://www.bbc.co.uk/rd/



More information about the Python-list mailing list