Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp

2012-03-02 Thread Xah Lee
Xah Lee wrote: «… One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. …» Chris Angelico wrote: «Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". …» they are com

Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-03-01 Thread WJ
Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > > > What's “In-place Algorithm”? > > Xah Le

Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp

2012-03-01 Thread Chris Angelico
On Fri, Mar 2, 2012 at 9:04 AM, Xah Lee wrote: > One easy > way to measure it is whether a programer can read and understand a > program without having to delve into its idiosyncrasies. Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". These a

Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-03-01 Thread Rainer Weikusat
Xah Lee writes: [...] > similarly, in perl, either one > require POSIX; floor(x/y); > the require POSIX instead of Math is a quirk. But even, floor should > really be builtin. > or > using a perl hack > int(x/y) > > all of the above are quirks. They rely on computer engineering by- > products (s

Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp

2012-03-01 Thread Xah Lee
On Mar 1, 7:04 am, Kaz Kylheku wrote: lisp: (floor (/ x y)) --[rewrite]--> (floor x y) Thanks for this interesting point. I don't think it's a good lang design, more of a lang quirk. similarly, in Python 2.x, x/y will work when both x and y are integers. Also, x//y works too, but that // is j

Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-03-01 Thread Rainer Weikusat
Xah Lee writes: [...] > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for “floor” > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLe

Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread WJ
Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > > > What's “In-place Algorithm”? > > Xah Le

Re: Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Evan Driscoll
On 2/29/2012 23:05, Dan Stromberg wrote: > > On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee > wrote: > > This page tells you what's “In-place algorithm”, using {python, perl, > emacs lisp} code to illustrate. > > Aren't in-place reversals rather non-functional? There

Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Xah Lee
On Feb 29, 9:01 pm, Steven D'Aprano wrote: > You don't need a temporary variable to swap two values in > Python. A better way to reverse a list using more Pythonic idioms is: > > for i in range(len(list_a)//2): >     list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i] forgive me sir, but i haven't

Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Dan Stromberg
On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > > > What's “In-pla

Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Steven D'Aprano
On Wed, 29 Feb 2012 20:07:49 -0800, Xah Lee wrote: > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", &

lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

2012-02-29 Thread Xah Lee
fun example. in-place algorithm for reversing a list in Perl, Python, Lisp http://xahlee.org/comp/in-place_algorithm.html plain text follows What's “In-place Algorithm”? Xah Lee, 2012-02-29 This page tells you what's “In-place algorithm”, usi

Re: Reversing a List

2010-09-02 Thread Victor Subervi
On Wed, Sep 1, 2010 at 9:26 AM, Shashwat Anand wrote: > > > On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton wrote: > >> On Wed, 1 Sep 2010 09:00:03 -0400 >> Victor Subervi wrote: >> >> > Hi; >> > I have this code: >> > >> > cursor.execute('describe products;') >> > cols = [item[0] for item in cu

Re: Reversing a List

2010-09-01 Thread Dave Angel
Victor Subervi wrote: Hi; I have this code: cursor.execute('describe products;') cols = [item[0] for item in cursor] cols = cols.reverse() cols.append('Delete') cols = cols.reverse() Unfortunately, the list doesn't reverse. If I print cols after the first reverse(), it prints None. Pl

Re: Reversing a List

2010-09-01 Thread Shashwat Anand
On Wed, Sep 1, 2010 at 6:45 PM, Matt Saxton wrote: > On Wed, 1 Sep 2010 09:00:03 -0400 > Victor Subervi wrote: > > > Hi; > > I have this code: > > > > cursor.execute('describe products;') > > cols = [item[0] for item in cursor] > > cols = cols.reverse() > > cols.append('Delete') > > co

Re: Reversing a List

2010-09-01 Thread Victor Subervi
On Wed, Sep 1, 2010 at 9:17 AM, Shashank Singh < shashank.sunny.si...@gmail.com> wrote: > reverse reverses in-place > > >>> l = [1, 2, 3] > >>> r = l.reverse() > >>> r is None > True > >>> l > [3, 2, 1] > >>> > Ah. Thanks! beno -- http://mail.python.org/mailman/listinfo/python-list

Re: Reversing a List

2010-09-01 Thread Shashank Singh
reverse reverses in-place >>> l = [1, 2, 3] >>> r = l.reverse() >>> r is None True >>> l [3, 2, 1] >>> On Wed, Sep 1, 2010 at 6:30 PM, Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() >

Re: Reversing a List

2010-09-01 Thread Matt Saxton
On Wed, 1 Sep 2010 09:00:03 -0400 Victor Subervi wrote: > Hi; > I have this code: > > cursor.execute('describe products;') > cols = [item[0] for item in cursor] > cols = cols.reverse() > cols.append('Delete') > cols = cols.reverse() > > Unfortunately, the list doesn't reverse. If I pr

Reversing a List

2010-09-01 Thread Victor Subervi
Hi; I have this code: cursor.execute('describe products;') cols = [item[0] for item in cursor] cols = cols.reverse() cols.append('Delete') cols = cols.reverse() Unfortunately, the list doesn't reverse. If I print cols after the first reverse(), it prints None. Please advise. Also, is th