You could simply use a regex to capture the elements between brackets, and then parse these using .split(',')
and float
to parse them to floats. Like:
for match in re.findall(r'(?<=\().*?(?=\))',schoolAddressString):
a,b = map(float,match.split(','))
# do something with a and b, for example
print([a,b])
This prints:
>>> for match in re.findall(r'(?<=\().*?(?=\))',schoolAddressString):
... a,b = map(float,match.split(','))
... # do something with a and b, for example
... print([a,b])
...
[54.4433, -112.3554]
Furthermore here you parse a float
. Therefore I think that the parsing will be less error prone: there will be more patterns that can be parsed, and the parsing is probably done correctly.
The result of the map(..)
is a list. So in case there can be an arbitrary number of values between the brackets, you can use values = map(..)
and then process the elements in values
.
Float pattern
The pattern the float(..)
constructor can parse is described in the documentation:
sign ::= "+" | "-"
infinity ::= "Infinity" | "inf"
nan ::= "nan"
numeric_value ::= floatnumber | infinity | nan
numeric_string ::= [sign] numeric_value
floatnumber ::= pointfloat | exponentfloat
pointfloat ::= [digitpart] fraction | digitpart "."
exponentfloat ::= (digitpart | pointfloat) exponent
digitpart ::= digit (["_"] digit)*
fraction ::= "." digitpart
exponent ::= ("e" | "E") ["+" | "-"] digitpart
digit ::= "0"..."9"
So the "added" value of using the constructor is that underscores are allowed as well (to separate groups of digits), and furthermore values like infinity
, inf
and nan
are also allowed.