Re: How to make a reverse for loop in python?

2008-09-21 Thread Alex Snast
On Sep 21, 3:47 am, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Sat, 20 Sep 2008 16:27:41 -0700, Alex Snast wrote: > > Another quick question please, is the List data structure just a dynamic > > array? If so how can you use static size array, linked list, AVL trees > > etcet

Re: How to make a reverse for loop in python?

2008-09-20 Thread Steven D'Aprano
On Sun, 21 Sep 2008 01:56:59 +0200, Christian Heimes wrote: > Just *don't* try to abuse lists by creating fancy stuff e.g. linked > lists. The memory overhead is going to kill your app. I agree with your advice not to abuse lists, but not for the reason you give. The memory overhead of a linked

Re: How to make a reverse for loop in python?

2008-09-20 Thread Steven D'Aprano
On Sat, 20 Sep 2008 16:27:41 -0700, Alex Snast wrote: > Another quick question please, is the List data structure just a dynamic > array? If so how can you use static size array, linked list, AVL trees > etcetera. Before I answer your question, I should say that you can go a LONG way with just t

Re: How to make a reverse for loop in python?

2008-09-20 Thread bearophileHUGS
Christian Heimes: > Unless you have specific needs for highly specialized data types, use lists. There's also the collections.deque for other related purposes. (I suggest people willing to look at some nice C code to read the sources of deque, Hettinger has created some refined code, very readabl

Re: How to make a reverse for loop in python?

2008-09-20 Thread Steven D'Aprano
On Sat, 20 Sep 2008 16:22:31 -0700, Alex Snast wrote: > That's a lot of responses guys. Thanks a lot i think i got it. Another > question, are there any pointers in python (or iterators) for when i use > a data structure that doesn't support random access? That surely depends on the data structu

Re: How to make a reverse for loop in python?

2008-09-20 Thread Gabriel Genellina
En Sat, 20 Sep 2008 20:27:41 -0300, Alex Snast <[EMAIL PROTECTED]> escribió: Another quick question please, is the List data structure just a dynamic array? If so how can you use static size array, linked list, AVL trees etcetera. Yes, lists are implemented as dynamic arrays (but you shouldn't

Re: How to make a reverse for loop in python?

2008-09-20 Thread Christian Heimes
Alex Snast wrote: Another quick question please, is the List data structure just a dynamic array? If so how can you use static size array, linked list, AVL trees etcetera. You should treat Python lists as an opaque item. You shouldn't concern yourself with the implementation details. Python li

Re: How to make a reverse for loop in python?

2008-09-20 Thread Alex Snast
On Sep 20, 8:13 pm, [EMAIL PROTECTED] wrote: > Duncan Booth: > > > > e.g. the python equivalent to the c++ loop > > > for (i = 10; i >= 0; --i) > > > The exact equivalent would be: > >         for i in range(10, -1, -1): print i > > I'd use xrange there. Anyway, I have always felt that Python synta

Re: How to make a reverse for loop in python?

2008-09-20 Thread Alex Snast
On Sep 20, 8:13 pm, [EMAIL PROTECTED] wrote: > Duncan Booth: > > > > e.g. the python equivalent to the c++ loop > > > for (i = 10; i >= 0; --i) > > > The exact equivalent would be: > >         for i in range(10, -1, -1): print i > > I'd use xrange there. Anyway, I have always felt that Python synta

Re: How to make a reverse for loop in python?

2008-09-20 Thread bearophileHUGS
Duncan Booth: > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) > > The exact equivalent would be: > for i in range(10, -1, -1): print i I'd use xrange there. Anyway, I have always felt that Python syntax not easy to understand at first sight, expecially when you

Re: How to make a reverse for loop in python?

2008-09-20 Thread Peter Otten
Gary Herron wrote: > Or you can create a new reversed (copy of the original) list and iterate > through it > > for item in reversed(L): >   print item It's not a copy, it's a view: >>> items = [1,2,3] >>> r = reversed(items) >>> items[:] = "abc" >>> for item in r: print item ... c b a Peter -

Re: How to make a reverse for loop in python?

2008-09-20 Thread Fredrik Lundh
Fredrik Lundh wrote: e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) use range with a negative step: for i in range(10-1, -1, -1): ... or just reverse the range: for i in reversed(range(10)): ... (and to include the 10 in the range, add one to

Re: How to make a reverse for loop in python?

2008-09-20 Thread Gary Herron
Alex Snast wrote: Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) -- http://mail.python.org/mailman/listinfo/python-list What are you trying to loop through? If it's the contents

Re: How to make a reverse for loop in python?

2008-09-20 Thread Fredrik Lundh
Alex Snast wrote: I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) use range with a negative step: for i in range(10-1, -1, -1): ... or just reverse the range: for i in r

Re: How to make a reverse for loop in python?

2008-09-20 Thread Simon Brunning
2008/9/20 Alex Snast <[EMAIL PROTECTED]>: > I'm new to python and i can't figure out how to write a reverse for > loop in python > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) for i in range(10, 0, -1): print i -- Cheers, Simon B. -- http://mail.python.org/mailm

Re: How to make a reverse for loop in python?

2008-09-20 Thread Duncan Booth
Alex Snast <[EMAIL PROTECTED]> wrote: > Hello > > I'm new to python and i can't figure out how to write a reverse for > loop in python > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) > The exact equivalent would be: for i in range(10, -1, -1): print i ex

Re: How to make a reverse for loop in python?

2008-09-20 Thread Mensanator
On Sep 20, 11:16�am, Alex Snast <[EMAIL PROTECTED]> wrote: > Hello > > I'm new to python and i can't figure out how to write a reverse for > loop in python > > e.g. the python equivalent to the c++ loop > > for (i = 10; i >= 0; --i) >>> for i in xrange(10,-1,-1): print i, 10 9 8 7 6 5 4 3 2 1 0

Re: How to make a reverse for loop in python?

2008-09-20 Thread Thoma
Alex Snast a écrit : Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) for (i = 0; i < 10; i--) -> for i in range(10): for (i = 10; i >= 0; --i) -> for i in range(10,-1,-1): Thoma --

How to make a reverse for loop in python?

2008-09-20 Thread Alex Snast
Hello I'm new to python and i can't figure out how to write a reverse for loop in python e.g. the python equivalent to the c++ loop for (i = 10; i >= 0; --i) -- http://mail.python.org/mailman/listinfo/python-list