deleting the first and the last character of a string

Cliff Wells LogiplexSoftware at earthlink.net
Wed Sep 11 17:31:52 EDT 2002


On Wed, 2002-09-11 at 13:50, Cliff Wells wrote:

> >>> def chopd(s, d):
> ...     s = s.strip()
> ...     return s[s[0] == d : {0:len(s), 1:-1}[s[-1] == d]]

Er, slightly better:

          return s[s[0] == d : (len(s), -1)[s[-1] == d]]

(Note to self: dictionaries aren't answer to everything...)

-- 
Cliff Wells, Software Engineer
Logiplex Corporation (www.logiplex.net)
(503) 978-6726 x308  (800) 735-0555 x308





More information about the Python-list mailing list