[EMAIL PROTECTED] wrote:
> Sure, you're right I forgot about rsplit !
> I guess the negative indexes & al could be done with
>
> sep.join(xyz.split(sep)[:index])
For index=-1 use
xyz.rsplit(sep, 1)[0]
Kent
--
http://mail.python.org/mailman/listinfo/python-list
Sure, you're right I forgot about rsplit !
I guess the negative indexes & al could be done with
sep.join(xyz.split(sep)[:index])
Thanks !
--
http://mail.python.org/mailman/listinfo/python-list
Fredrik Lundh wrote:
> [EMAIL PROTECTED] wrote:
>
>
>>I often need to re-code for myself a small code snippet to define
>>string.upto() and string.from(), which are used like :
FWIW this is pretty easy to do with str.split() and rsplit():
>>
>># canonical exa
[EMAIL PROTECTED] wrote:
> I often need to re-code for myself a small code snippet to define
> string.upto() and string.from(), which are used like :
>
> # canonical examples
> > "1234456789".upto("45")
> '1234'
> > "123456dd9
On 22/03/06, Tim Williams (gmail) <[EMAIL PROTECTED]> wrote:
> if u"h" in u"hello, world !" and u"hello, world !".from("h"):
> return " u"hello, world !"
>else: # not really required, used for demonstration only
> return
:)
OK, python allows me to code faster than I can think ( n
[EMAIL PROTECTED] wrote:
> I often need to re-code for myself a small code snippet to define
> string.upto() and string.from(), which are used like :
>
> Nothing very complicated to make with find and rfind, but wouldn't this
> be handy to have it ready in the common string
On 22 Mar 2006 06:41:32 -0800, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
I often need to re-code for myself a small code snippet to definestring.upto() and
string.from(), which are used like :
[snip]
# if not found, return whole string> "hello, world !".upto("#")
"hello, world !"> u"hello, wo
I often need to re-code for myself a small code snippet to define
string.upto() and string.from(), which are used like :
# canonical examples
> "1234456789".upto("45")
'1234'
> "123456dd987".from('d')
'd987'
# if not found, ret