String Formatting

Pontus Ekberg herrekberg at users.sf.net
Thu Aug 10 08:54:14 EDT 2006


On Thu, 10 Aug 2006 05:35:26 -0700, OriginalBrownster wrote:

> Hi there:
> 
> I was wondering if its at all possible to search through a string for a
> specific character.
> 
> I want to search through a string backwords and find the last
> period/comma, then take everything after that period/comma
> 
> Example
> 
> If i had a list:    bread, butter, milk
> 
> I want to just take that last entry of milk. However the need for it
> arises from something more complicated.
> 
> Any help would be appreciated


>>> s='bread, butter, milk'
>>> s.rsplit(',', 1)[-1]
' milk'
>>> s.rsplit(',', 1)[-1].strip()
'milk'


Hope that helps.




More information about the Python-list mailing list