[Tutor] Remove some known text around text I need to keep

Joel Goldstick joel.goldstick at gmail.com
Wed Jan 29 16:09:41 EST 2020


On Wed, Jan 29, 2020 at 1:51 PM Robert Alexander <gogonegro at gmail.com> wrote:
>
> Thanks Alan,
> Good to learn :)
>
> I’ll look into it even though at a later reflection I might do this without
> python with just an awk command killing all [TAG: and ] chars from the
> files :)
>
> Take care,
> Robert
>
>
> On 29 January 2020 at 19:46:55, Alan Gauld via Tutor (tutor at python.org)
> wrote:
>
> On 29/01/2020 16:37, Robert Alexander wrote:
> ]
> > [SINTOMO: paziente sintomatica per dispnea moderata]
> > [SEGNO: Non edemi]
> > [SEGNO: calo di 2 kg (55,8 kg)]
> > [TERAPIA: ha ridotto la terapia diuretica]
>
> > the same lines as above what I need to write back in the new “clean”
> files are like the following:
>
> > paziente sintomatica per dispnea moderata]
> > Non edemi]
> > calo di 2 kg (55,8 kg)]
> > ha ridotto la terapia diuretica]
>
> Look at the partition method of strings:
>
> partition(...)
> S.partition(sep) -> (head, sep, tail)
>
> Search for the separator sep in S, and return the part before it,
> the separator itself, and the part after it. If the separator is not
> found, return S and two empty strings.
>
>
> Example:
>
> >>> "FRED: Heris a partition: that looks like s".partition(':')
> ('FRED', ':', ' Heris a partition: that looks like s')
> >>>
>
> It should work with embedded \n too.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

I didn't know about str.partition, but in your case str.split(":")
will return a list with the part you don't want first, followed by the
part you want

>>> s = "[SEGNO: edemi declivi >> a sinistra]"
>>> s.split(":")
['[SEGNO', ' edemi declivi >> a sinistra]']
>>>


-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays


More information about the Tutor mailing list