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

DL Neil PyTutor at danceswithmice.info
Wed Jan 29 17:05:04 EST 2020


>>> [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)
...
> 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]']


Some call it "pedantry", others "attention to detail" but don't forget 
the closing square-bracket!

Depending upon the read-mechanism (whether the end-of-line character(s) 
are included - NB OpSys variations then apply!), a string-slice to 
remove the last character(s), possibly even before the above, will 
do-the-trick!
-- 
Regards =dn


More information about the Tutor mailing list