Hii all ,
I have a file like that
00:00:08
ss ssone 32.0
ssone sstwo 33.0
sstwo ssthree 35.0
11:12:13
ssfour ssfive 34.0
ssthree sssix 38.0
ssnine ssseven 39.0
13:12:11
I want to get all the numbers explicitely.
Desired output will be
00
00
08
32.0
33.0
35.0
11
12
13
and so on.
Could you please tell me how do i can write the code ?
file = '''00:00:08
ss ssone 32.0
ssone sstwo 33.0
sstwo ssthree 35.0
11:12:13
ssfour ssfive 34.0
ssthree sssix 38.0
ssnine ssseven 39.0
13:12:11
'''
file_list = file.split()
output = []
for item in file_list:
if item[0].isdigit():
if item.find(':') > 0:
output += [n for n in item.split(':')]
else:
output.append(item)
for n in output:
print(n)
The ‘file’ here is simulated, rater than being read and the ‘numbers’ are held in string objects, but both of those points can be addressed, if needs be.
Edit: Changed regex from (\d+(?:\.\d){0,1}) to (\d+(?:\.\d+){0,1}) to capture all of numbers past the decimal like 32.589 rather than capturing 32.5 and 89.
Thank you. The program is printing only the integer values splitted by :. I need to extract the float numbers also. And I have to read these datas from a file.