strmap

sisl.utils.strmap(func, s, start=None, end=None, sep='b')[source]

Parse a string as though it was a slice and map all entries using func.

Parameters
funcfunction

function to parse every match with

sstr

the string that should be parsed

startoptional

the replacement in case the LHS of the delimiter is not present

endoptional

the replacement in case the RHS of the delimiter is not present

sep{‘b’, ‘c’}

separator used, 'b' is square brackets, 'c', curly braces

Examples

>>> strmap(int, '1')
[1]
>>> strmap(int, '1-2')
[(1, 2)]
>>> strmap(int, '1-')
[(1, None)]
>>> strmap(int, '1-', end=4)
[(1, 4)]
>>> strmap(int, '1-10[2-3]')
[((1, 10), [(2, 3)])]