Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45432
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.015 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'string': 0.09; 'specified,': 0.09; 'underscore': 0.09; 'subject:question': 0.10; 'delimiter': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'given,': 0.16; 'separator.': 0.16; 'splits': 0.16; 'wrote:': 0.18; 'split': 0.19; '>>>': 0.22; 'string,': 0.24; 'appreciated': 0.26; 'skip:" 40': 0.26; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'function': 0.29; 'am,': 0.29; 'words': 0.29; 'message-id:@mail.gmail.com': 0.30; 'work.': 0.31; "skip:' 10": 0.31; 'sep': 0.31; 'fri,': 0.33; 'done.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'list': 0.37; 'easily': 0.37; 'starting': 0.37; 'skip:[ 10': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'most': 0.60; '1:00': 0.84; 'front.': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=YtYZvm48fvTp6M6X2Hh054qpnea2OS/3Ut7VYsWIGT8=; b=UPBKX10ZKtozioufh/SLFK0NUK2vJSLY6PlYJqnzobzeHAP1sBKa4nlW2U1nl0t9i/ pukYXPTL6tdgmI0zqxtY5AmDJzDeMKknz7+7IgKy3s7oTsZSQ4VOxPvvCJSDKiWbVc8T sc+qvG+2PlmqZIM/q4ma//Nfdlsq+G/jWgzK1ScW2PHAFhZFtmQnTqKRqnibU67Tjlkz 4V6Kq6lqfd8jRi8Cprh+oqnyMfbbnTBZ+U8gcMGQgADyWBWsMnPCcuKd8xSk5JRsI9tw YIaDlrJoczf8FM089VBnd3CcpKeiQ0Zu7AKzFa8Mffelb/RLTO7atKCSGxoQE6kog9ba joVg== |
| MIME-Version | 1.0 |
| X-Received | by 10.220.167.69 with SMTP id p5mr26560974vcy.57.1368717339331; Thu, 16 May 2013 08:15:39 -0700 (PDT) |
| In-Reply-To | <d8c03de0-dc35-45e3-a6b2-2af39feb9e79@googlegroups.com> |
| References | <d8c03de0-dc35-45e3-a6b2-2af39feb9e79@googlegroups.com> |
| Date | Fri, 17 May 2013 01:15:39 +1000 |
| Subject | Re: spilt question |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1757.1368717347.3114.python-list@python.org> (permalink) |
| Lines | 32 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1368717347 news.xs4all.nl 15966 [2001:888:2000:d::a6]:35764 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:45432 |
Show key headers only | View raw
On Fri, May 17, 2013 at 1:00 AM, loial <jldunn2000@gmail.com> wrote:
> I want to split a string so that I always return everything BEFORE the LAST underscore
>
> HELLO_xxxxxxxx.lst # should return HELLO
> HELLO_GOODBYE_xxxxxxxx.ls # should return HELLO_GOODBYE
>
> I have tried with rsplit but cannot get it to work.
>
> Any help appreciated
Try with a limit:
>>> "HELLO_GOODBYE_xxxxxxxx.ls".rsplit("_",1)
['HELLO_GOODBYE', 'xxxxxxxx.ls']
>>> "HELLO_GOODBYE_xxxxxxxx.ls".rsplit("_",1)[0]
'HELLO_GOODBYE'
You can easily get docs on it:
>>> help("".rsplit)
Help on built-in function rsplit:
rsplit(...)
S.rsplit(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the
delimiter string, starting at the end of the string and
working to the front. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified, any whitespace string
is a separator.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
spilt question loial <jldunn2000@gmail.com> - 2013-05-16 08:00 -0700 Re: spilt question Walter Hurry <walterhurry@lavabit.com> - 2013-05-16 15:10 +0000 Re: spilt question Fábio Santos <fabiosantosart@gmail.com> - 2013-05-16 16:14 +0100 Re: spilt question Chris Angelico <rosuav@gmail.com> - 2013-05-17 01:15 +1000 Re: spilt question Dave Angel <davea@davea.name> - 2013-05-16 11:20 -0400 Re: spilt question Tim Chase <python.list@tim.thechases.com> - 2013-05-16 10:23 -0500 Re: spilt question Ned Batchelder <ned@nedbatchelder.com> - 2013-05-16 11:22 -0400 Re: spilt question Dave Angel <davea@davea.name> - 2013-05-16 11:32 -0400
csiph-web