Questions on Using Python to Teach Data Structures and Algorithms
Brendon Towle
btowle at carnegielearning.com
Thu Sep 28 13:01:54 EDT 2006
On 28 Sep 2006, at 12:45 PM, python-list-request at python.org wrote:
> From: "MonkeeSage" <MonkeeSage at gmail.com>
> Subject: Re: Questions on Using Python to Teach Data Structures and
> Algorithms
> To: python-list at python.org
>
> [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.
More information about the Python-list
mailing list