[Edu-sig] Re: In defense of 0, was Re: None potato, one potato,
two potato, more..
Fred Yankowski
fred at ontosys.com
Mon Jan 5 12:59:00 EST 2004
On Mon, Jan 05, 2004 at 10:25:09AM -0700, Trent Oliphant wrote:
> So the indexing notation [n] could be considered shorthand for [n:n+1]?
> You are taking a slice of len 1 starting at n?
But where [n:n+1] is a sequence of length 1, [n] is the object in that
sequence.
>>> x = ['a', 'b', 'c', 'd']
>>> x[2:3]
['c']
>>> x[2]
'c'
If Python had a 'first' method for sequences, similar to 'car' in
Lisp, then x[n] would be roughly equivalent to x[n:n+1].first().
--
Fred Yankowski fred at ontosys.com tel: +1.630.879.1312
OntoSys, Inc PGP keyID: 7B449345 fax: +1.630.879.1370
www.ontosys.com 38W242 Deerpath Rd, Batavia, IL 60510-9461, USA
More information about the Edu-sig
mailing list