[Solved] isolate data from a string


This code:

inp = "((Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (0, 0, 0)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-38.805, 0, 1333.283)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-77.609, 0, 2666.566)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-116.414, 0, 3999.849)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-155.218, 0, 5333.133)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-194.023, 0, 6666.416)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0) ; v3: (0, 0, 1); off: (-232.827, 0, 7999.699)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-271.632, 0, 9332.982)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-310.436, 0, 10666.265)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-349.241, 0, 11999.548)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-388.045, 0, 13332.832)),Matrix(v1: (1, 0, 0); v2: (0, 1, 0); v3: (0, 0, 1); off: (-426.85, 0, 14666.115))"

lst = inp.split(";")
for s in lst:
    s.strip()
    if s.find("off:") > -1:
        data = s.split(")")
        print(data[0][7:])

will produce:

0, 0, 0
-38.805, 0, 1333.283
-77.609, 0, 2666.566
-116.414, 0, 3999.849
-155.218, 0, 5333.133
-194.023, 0, 6666.416
-232.827, 0, 7999.699
-271.632, 0, 9332.982
-310.436, 0, 10666.265
-349.241, 0, 11999.548
-388.045, 0, 13332.832
-426.85, 0, 14666.115

Note: I did not use list comprehension or generators – to make the code as plain as possible.

1

solved isolate data from a string