On 28 Sep 2006, at 12:45 PM, [EMAIL PROTECTED] wrote: > From: "MonkeeSage" <[EMAIL PROTECTED]> > Subject: Re: Questions on Using Python to Teach Data Structures and > Algorithms > To: python-list@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. -- http://mail.python.org/mailman/listinfo/python-list