Questions on Using Python to Teach Data Structures and Algorithms
btowle at carnegielearning.com
Thu Sep 28 19:01:54 CEST 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
> To: python-list at python.org
> 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:
res = [a]
because cons is supposed to leave its second argument untouched.
Brendon Towle, PhD
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