Re: Questions on Using Python to Teach Data Structures and Algorithms



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.


.



Relevant Pages

  • Re: Whos to blame?
    ... wxPython 2.8.6.1's XRCed tool from a XRC file which in turn is ... def OnInit: ... global __res ... set additional window styles using SetWindowStyleand ...
    (comp.lang.python)
  • Whos to blame?
    ... def OnInit: ... global __res ... Override it for custom setup before the window is created ... set additional window styles using SetWindowStyleand ...
    (comp.lang.python)
  • [ANN] MLTypes: ML-style qualified unions for ruby
    ... def initialize ... @alts = alts ...
    (comp.lang.ruby)
  • Re: [RFC 0/5] sched: Add CPU rate caps
    ... selection and only one scheduler is in force. ... using Stacked Git for the patch development? ... res, so, se = gquilt_utils.run_cmd ... def is_patch_applied: ...
    (Linux-Kernel)
  • Pattern-matching for method arguments in Ruby
    ... def reverse ... you can't say something like "argument 1 should be array with first ... #Empty array means "pattern matched, ... res += r ...
    (comp.lang.ruby)