>>> s = 'PBUSH 201005 K 500 1. 1. 1. 1. 1.' #Your original string here
>>> l #Create your desired list ['500.2', '5.2', '5.3', '5.4', '5.5', '5.6', '5.7'] >>> lsep = s.count(' 1.') #Count the occurrence of seperators >>> for i in range(lsep): #Replace all of them by values in list l, one by one ... f = s.find(' 1.') ... s = s[:f] + l[i] + s[f+3:] ... >>> s #Your final string 'PBUSH 201005 K 500 500.2 5.2 5.3 5.4 5.5' ~l0nwlf On Wed, Mar 3, 2010 at 12:36 PM, Ben Racine <i3enha...@gmail.com> wrote: > All, > > Say I have a string "l" ... > > l = 'PBUSH 201005 K 1. 1. 1. 1. 1. > 1.' > > And I want to replace the first " 1." with a "500.2" and the second " > 1." with " 5.2" ... > > What pythonic means would you all recommend? > > Note the whitespace is equal between the existing substring and the > replacement string. > > Many thanks, > Ben Racine > i3enha...@gmail.com > > > > -- > http://mail.python.org/mailman/listinfo/python-list >
-- http://mail.python.org/mailman/listinfo/python-list