Inserting '-' character in front of all numbers in a string

Michael Bentley michael at jedimindworks.com
Fri Mar 30 19:17:23 EDT 2007


On Mar 30, 2007, at 5:42 PM, Michael Bentley wrote:
> for i in yourstring.split():
> 	if i[0].isdigit():
> 		yourstring = yourstring.replace(i, '-%s' % (i,), 1)

*OR*

yourstring ' '.join(x[0].isdigit() and '-%s' % x or x for x in  
yourstring.split())

;-)





More information about the Python-list mailing list