Re: nonunique string replacements

2010-03-03 Thread Peter Otten
Ben Racine wrote: > 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? With regular

Re: nonunique string replacements

2010-03-03 Thread Steven D'Aprano
On Tue, 02 Mar 2010 23:06:13 -0800, Ben Racine 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

Re: nonunique string replacements

2010-03-02 Thread Shashwat Anand
>>> 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):#Repla

nonunique string replacements

2010-03-02 Thread Ben Racine
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 ex