def _parse_string_to_list_of_pairs ( s , seconds_to_int = False ) : ret = [ ] for p in [ s . split ( ":" ) for s in re . sub ( "[,.;]" , " " , s ) . split ( ) ] : if len ( p ) != 2 : raise ValueError ( "bad input to _parse_string_to_list_of_pairs %s" % s ) if seconds_to_int : ret . append ( ( p [ 0 ] , int ( p [ 1 ] ) ) ) else : ret . append ( tuple ( p ) ) return ret
split the string into pairs python
r Parses a string into a list of pairs .
def _parse_string_to_list_of_pairs(s, seconds_to_int=False):
  r"""Parses a string into a list of pairs.

  In the input string, each pair is separated by a colon, and the delimiters
  between pairs are any of " ,.;".

  e.g. "rows:32,cols:32"

  Args:
    s: str to parse.
    seconds_to_int: Boolean. If True, then the second elements are returned
      as integers;  otherwise they are strings.

  Returns:
    List of tuple pairs.

  Raises:
    ValueError: Badly formatted string.
  """
  ret = []
  for p in [s.split(":") for s in re.sub("[,.;]", " ", s).split()]:
    if len(p) != 2:
      raise ValueError("bad input to _parse_string_to_list_of_pairs %s" % s)
    if seconds_to_int:
      ret.append((p[0], int(p[1])))
    else:
      ret.append(tuple(p))
  return ret