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: - func : function
function to parse every match with
- s : str
the string that should be parsed
- start : optional
the replacement in case the LHS of the delimiter is not present
- end : optional
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)])]