Questions on Using Python to Teach Data Structures and Algorithms
Bruno Desthuilliers
onurb at xiludom.gro
Thu Sep 28 07:24:44 EDT 2006
Brendon Towle wrote:
> Some of your Lisp translations are subtly off...
Seems correct to me. Lisp lists are linked lists, not arrays.
>
>> Date: 28 Sep 2006 02:49:50 -0700
>> From: "sturlamolden" <sturlamolden at yahoo.no>
>> Subject: Re: Questions on Using Python to Teach Data Structures and
>> Algorithms
>> To: python-list at python.org
>>
>> If you want to make a chained structure, then perhaps you know LISP?
>> This is what the basic machinery of LISP looks like in Python:
>>
>> def cons(a,b)
>> return [a,b]
>
> should be:
> return [a].extend(b)
A Lisp cons is made of a reference to it's content and a reference to
the rest of the list, so cons = lambda a, b : [a, b] seems the most
straightforward translation.
>> def car(structure)
>> return structure[0]
>>
>> def cdr(structure)
>> return structure[1]
>
> should be:
> return structure[1:]
idem.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list