[Tutor] Remove some known text around text I need to keep
Alan Gauld
alan.gauld at yahoo.co.uk
Wed Jan 29 18:28:32 EST 2020
On 29/01/2020 21:09, Joel Goldstick wrote:
> 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
The problem with split is that if the string has a colon in it
split will split into 3 parts, not 2. You can specify the maxsplits
but that’s extra complexity. Partition only splits on the first occurrence.
split also loses the separator - although not an isssue here - but
partition retains the whole string.
--
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
More information about the Tutor
mailing list