Steven D'Aprano wrote:
On Sun, 18 Dec 2005 04:50:20 -0800, Max Erickson wrote:
j is a built-in object used to make complex numbers. Or at least it
was, until you rebound it to the current element from myarray. That's bad
practice, but since using complex numbers is rather unusual, one you
Joseph Garvin [EMAIL PROTECTED] writes:
And this way I can keep referring to j instead of myarray[i], but I'm
still forced to use myarray[i-1] and myarray[i+1] to refer to the
previous and next elements. Being able to do j.prev, j.next seems more
intuitive.
Is there some other builtin
Paul Rubin http://[EMAIL PROTECTED] writes:
elts = iter(myarray)
prev,cur,next = elts.next(),elts.next(),elts.next()
for next2 in elts:
do_something_with (prev, cur, next)
prev,cur,next = cur, next, next2
Of course these fail when there's less than 3 elements.
Ehh,
Bengt Richter wrote:
def pcniter(seq, NULL=NotImplemented):
... seqiter = iter(seq)
... prev = curr = NULL
... try: next = seqiter.next()
... except StopIteration: return
... for item in seqiter:
... prev, curr, next = curr, next, item
... yield prev,
When I first came to Python I did a lot of C style loops like this:
for i in range(len(myarray)):
print myarray[i]
Obviously the more pythonic way is:
for i in my array:
print i
The python way is much more succinct. But a lot of times I'll be looping
through something, and if a
Joseph Garvin [EMAIL PROTECTED] wrote:
When I first came to Python I did a lot of C style loops like this:
for i in range(len(myarray)):
print myarray[i]
Obviously the more pythonic way is:
for i in my array:
print i
The python way is much more succinct. But a lot of
On Sun, 18 Dec 2005 04:23:21 -0700, Joseph Garvin wrote:
When I first came to Python I did a lot of C style loops like this:
for i in range(len(myarray)):
print myarray[i]
Obviously the more pythonic way is:
for i in my array:
print i
The python way is much more succinct.
On Sun, 18 Dec 2005 23:36:29 +1100, Steven D'Aprano wrote:
Python lists aren't linked lists? They are arrays.
[slaps head for the stupid typo]
That should have been a full stop, not question mark. Python lists are not
linked lists, period.
--
Steven.
--
j is a built-in object used to make complex numbers. Or at least it
was, until you rebound it to the current element from myarray. That's bad
practice, but since using complex numbers is rather unusual, one you will
probably get away with.
Is it?
j
Traceback (most recent call last):
File
Just make a custom generator function:
def prevcurnext(seq):
it = iter(seq)
prev = it.next()
cur = it.next()
for next in it:
yield (prev,cur,next)
prev,cur = cur, next
for (a,b,c) in prevcurnext(range(10)):
print a,b,c
On Sun, 18 Dec 2005 04:50:20 -0800, Max Erickson wrote:
j is a built-in object used to make complex numbers. Or at least it
was, until you rebound it to the current element from myarray. That's bad
practice, but since using complex numbers is rather unusual, one you will
probably get away with.
On Sun, 18 Dec 2005 04:23:21 -0700, Joseph Garvin [EMAIL PROTECTED] wrote:
When I first came to Python I did a lot of C style loops like this:
for i in range(len(myarray)):
print myarray[i]
Obviously the more pythonic way is:
for i in my array:
print i
The python way is much more
Steven D'Aprano [EMAIL PROTECTED] wrote:
I can't speak for others, but I've never come upon a situation where I
needed to access the element before and the element after the current one.
[thinks...] Wait, no, there was once, when I was writing a parser that
iterated over lines. I needed
Steven D'Aprano wrote:
On Sun, 18 Dec 2005 23:36:29 +1100, Steven D'Aprano wrote:
Python lists aren't linked lists? They are arrays.
[slaps head for the stupid typo]
That should have been a full stop, not question mark. Python lists are not
linked lists, period.
All the more
14 matches
Mail list logo