espnet2.asr.state_spaces.utils.to_list
Less than 1 minute
espnet2.asr.state_spaces.utils.to_list
espnet2.asr.state_spaces.utils.to_list(x, recursive=False)
Convert an object to a list.
This function converts the input object to a list format. If the input is already a sequence (e.g., list, tuple, or ListConfig), it is returned as is. If the input is a non-sequence object and recursive is set to False, the object is wrapped in a list. If recursive is True, the function will convert each element of the input sequence to a list.
- Parameters:
- x (Any) – The object to convert to a list.
- recursive (bool) – If True, apply conversion recursively to elements of the input sequence. Defaults to False.
- Returns: The converted list object.
- Return type: list
Examples
>>> to_list([1, 2, 3])
[1, 2, 3]
>>> to_list((1, 2, 3))
[1, 2, 3]
>>> to_list(5)
[5]
>>> to_list([1, (2, 3)], recursive=True)
[1, [2, 3]]
>>> to_list("not a sequence")
["not a sequence"]
NOTE
This function treats strings as non-sequence objects. If the input is a string, it will be wrapped in a list regardless of the recursive parameter.