Re: Questions on Using Python to Teach Data Structures and Algorithms
- From: Brendon Towle <btowle@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 13:01:54 -0400
On 28 Sep 2006, at 12:45 PM, python-list-request@xxxxxxxxxx wrote:
From: "MonkeeSage" <MonkeeSage@xxxxxxxxx>
Subject: Re: Questions on Using Python to Teach Data Structures and
Algorithms
To: python-list@xxxxxxxxxx
[snip]
But Brendon's code also needs a correction: [a].extend(b) is wrong,
because extend is in-place and returns None, and [a] is anonymous...it
needs to be something like:
def cons(a, b):
b.insert(0, a)
return b
Clearly, my Lisp is better than my Python; I stand corrected. (Brings back memories of the "Why don't destructive sequence operations return the sequence?" thread.)
I think I'd probably prefer:
def cons(a,b):
res = [a]
res.extend(b)
return res
because cons is supposed to leave its second argument untouched.
B.
--
Brendon Towle, PhD
Cognitive Scientist
+1-412-690-2442x127
Carnegie Learning, Inc.
The Cognitive Tutor Company ®
Helping over 375,000 students in 1000 school districts succeed in math.
.
- Prev by Date: using the email module
- Next by Date: Re: Questions on Using Python to Teach Data Structures and Algorithms
- Previous by thread: Re: Questions on Using Python to Teach Data Structures and Algorithms
- Next by thread: ctypes pointer to pointer
- Index(es):
Relevant Pages
|