i'm newbie @ python.
so file has lines this:
-1 1:-0.294118 2:0.487437 3:0.180328 4:-0.292929 5:-1 6:0.00149028 7:-0.53117 8:-0.0333333
i need coming correct python code extract every float preceded colon , followed space (ex: [-0.294118, 0.487437,etc...]
)
i've tried datalist = re.findall(':(.\*) ', str(line))
, datalist = re.split(':(.\*) ', str(line))
these come whole line. i've been researching problem while appreciated. thanks!
try one:
:(-?\d\.\d+)\s
in code
p = re.compile(':(-?\d\.\d+)\s') m = p.match(str(line)) datalist = m.groups()
this more specific on want.
in case .* match can
test on regexr.com:
in case last element wasn't captured because doesnt have space follow, if problem remove \s regex