Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36155
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'string.': 0.04; 'that?': 0.05; 'subject:help': 0.07; 'python': 0.09; 'minus': 0.09; 'subject:skip:m 10': 0.09; 'subject:string': 0.09; 'sat,': 0.15; '7:35': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sign,': 0.16; 'wrote:': 0.17; 'jan': 0.18; 'followed': 0.20; 'assuming': 0.22; 'split': 0.23; 'header:In- Reply-To:1': 0.25; 'skip:" 20': 0.26; 'message- id:@mail.gmail.com': 0.27; 'that.': 0.30; 'skip:s 30': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'skip:. 20': 0.35; 'pm,': 0.35; 'received:209.85.220': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'characters': 0.36; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:( 30': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'remove': 0.61; 'subject:Need': 0.61; 'back': 0.62; 'subject:. ': 0.66; 'as:': 0.75; 'guaranteed': 0.76; '2013': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=UUE2KVHQLQjeIO00ET2Bm5C/nwZM8nPCgUT5jZaHRiM=; b=LdhMM6zScc+arRgdgWohMVnCWKRqRH0F5ndlk684C5ujPaFOmhmmUHCVc56vY0a3aF iRl9biKH+chWPzwSCmdYCcWTIDQwERT18RUWyP8vq3iE1grFPBVrLlj8xlQadfuNsuIz 8I/jFM5ooOmRFbbcDB/Xz4yqFMjf9UZKFzwoM77yfdnoIBbDNU0dR8WVDlcQKN2F7XxA WaR3HzRQH8yTA9UCQ3Jr6MyNHkH+k3UVoxMzYz1Q1/Pkpw5ZY6nBqfhXxhH8gffBY+AE o05Rhk9aviVsFfb7ahCY2eJuaCQ/gx3vu0yUx0lPrStYncEcymuYzKy5t5XmUXm8GPx1 qDYQ== |
| MIME-Version | 1.0 |
| In-Reply-To | <e480480d-f3b4-4491-969c-7d1843bf9e33@googlegroups.com> |
| References | <e480480d-f3b4-4491-969c-7d1843bf9e33@googlegroups.com> |
| Date | Sat, 5 Jan 2013 20:27:46 +1100 |
| Subject | Re: Need a specific sort of string modification. Can someone help? |
| 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.109.1357378077.2939.python-list@python.org> (permalink) |
| Lines | 27 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1357378077 news.xs4all.nl 6950 [2001:888:2000:d::a6]:52601 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:36155 |
Show key headers only | View raw
On Sat, Jan 5, 2013 at 7:35 PM, Sia <hossein.asgharian@gmail.com> wrote:
> I have strings such as:
>
> tA.-2AG.-2AG,-2ag
> or
> .+3ACG.+5CAACG.+3ACG.+3ACG
>
> The plus and minus signs are always followed by a number (say, i). I want python to find each single plus or minus, remove the sign, the number after it and remove i characters after that. So the two strings above become:
>
> tA..,
> and
> ...
>
> How can I do that?
Interesting. Are you guaranteed that there are no other plus or minus
signs? Is the number after the sign just one digit? Assuming the
answers to both are "yes", here's a one-liner:
s=".+3ACG.+5CAACG.+3ACG.+3ACG"
result = "".join([x[int(x[0])+1:] for x in ("0"+s).replace("-","+").split("+")])
Split on either - or +, then trim off that many characters from each
(that's the list comp), then join them back into a string.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Need a specific sort of string modification. Can someone help? Sia <hossein.asgharian@gmail.com> - 2013-01-05 00:35 -0800
Re: Need a specific sort of string modification. Can someone help? Frank Millman <frank@chagford.com> - 2013-01-05 11:15 +0200
Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-05 20:27 +1100
Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 09:30 -0500
Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 01:47 +1100
Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 10:03 -0500
Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 02:09 +1100
Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 10:38 -0500
Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 02:57 +1100
Re: Need a specific sort of string modification. Can someone help? Ian Kelly <ian.g.kelly@gmail.com> - 2013-01-05 13:04 -0700
Re: Need a specific sort of string modification. Can someone help? Chris Angelico <rosuav@gmail.com> - 2013-01-06 07:32 +1100
Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 15:47 -0500
Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-06 12:28 -0500
Re: Need a specific sort of string modification. Can someone help? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-01-06 23:19 +0000
Re: Need a specific sort of string modification. Can someone help? Roy Smith <roy@panix.com> - 2013-01-05 09:12 -0500
Re: Need a specific sort of string modification. Can someone help? Tim Chase <python.list@tim.thechases.com> - 2013-01-05 11:24 -0600
Re: Need a specific sort of string modification. Can someone help? Tim Chase <python.list@tim.thechases.com> - 2013-01-05 12:49 -0600
Re: Need a specific sort of string modification. Can someone help? Mitya Sirenef <msirenef@lightbird.net> - 2013-01-06 01:32 -0500
Re: Need a specific sort of string modification. Can someone help? Mitya Sirenef <msirenef@lightbird.net> - 2013-01-06 14:53 -0500
Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 18:48 -0800
Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 19:40 -0800
Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 21:28 -0800
Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 21:30 -0800
Re: Need a specific sort of string modification. Can someone help? John Ladasky <john_ladasky@sbcglobal.net> - 2013-01-06 21:39 -0800
Re: Need a specific sort of string modification. Can someone help? Nick Mellor <thebalancepro@gmail.com> - 2013-01-06 23:07 -0800
csiph-web