I have 2 strings:
s7="ONE : TWO : THREE : FOUR : FIVE 30.1 : SIX 288.3 : SEVEN 1.9 : EIGHT 45.3 :"
s8="ONE : TWO : THREE : FOUR 155.5 : FIVE 334.7 : SIX 6.7 : SEVEN 44.5 :"
I'm using the following code to parse it:
c=s.count(':')
if c==8:
res=""
res=s.split(' : ')
res = [item.strip() for item in s.split(':')]
for index, item in enumerate(res):
print index, item
if c==7:
res=""
res=s.split(' : ')
res = [item.strip() for item in s.split(':')]
for index, item in enumerate(res):
print index, item
This output i get is
>>> parse(s7)
0 ONE
1 TWO
2 THREE
3 FOUR
4 FIVE 30.1
5 SIX 288.3
6 SEVEN 1.9
7 EIGHT 45.3
8
>>> parse(s8)
0 ONE
1 TWO
2 THREE
3 FOUR 155.5
4 FIVE 334.7
5 SIX 6.7
6 SEVEN 44.5
7
How can I extract the numerical values from index 4 to 7 in s7 and index 3 to 6 in s8? I need to store these values so I can write them into a database later.
I've tried a couple of things but they aren't working.
Please help.
resare redundant