>>> s = 'PBUSH 201005 K 500 1. 1. 1. 1. 1.' #Your original string here<br><br>>>> l #Create your desired list<br>['500.2', '5.2', '5.3', '5.4', '5.5', '5.6', '5.7']<br>
<br>>>> lsep = s.count(' 1.') #Count the occurrence of seperators<br><br>>>> for i in range(lsep): #Replace all of them by values in list l, one by one<br>... f = s.find(' 1.')<br>
... s = s[:f] + l[i] + s[f+3:]<br>... <br>>>> s #Your final string<br>'PBUSH 201005 K 500 500.2 5.2 5.3 5.4 5.5'<br><br><br>~l0nwlf<br><br><div class="gmail_quote">
On Wed, Mar 3, 2010 at 12:36 PM, Ben Racine <span dir="ltr"><<a href="mailto:i3enhamin@gmail.com">i3enhamin@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
All,<br>
<br>
Say I have a string "l" ...<br>
<br>
l = 'PBUSH 201005 K 1. 1. 1. 1. 1. 1.'<br>
<br>
And I want to replace the first " 1." with a "500.2" and the second " 1." with " 5.2" ...<br>
<br>
What pythonic means would you all recommend?<br>
<br>
Note the whitespace is equal between the existing substring and the replacement string.<br>
<br>
Many thanks,<br>
Ben Racine<br>
<a href="mailto:i3enhamin@gmail.com">i3enhamin@gmail.com</a><br>
<font color="#888888"><br>
<br>
<br>
--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>