您可以使用str.split([sep[, maxsplit]])
返回词的列表的字符串,使用sep作为分隔符字符串。如果给出maxsplit,最多可以完成maxsplit分割(因此,列表最多只能有maxsplit + 1个元素)。如果未指定maxsplit或-1,则分割数量没有限制(所有可能的分割)。
应用
>> ' 1 2 3 '.split()
['1', '2', '3']
在 “串联” 与str.replace(old, new[, count])
返回字符串的子串用旧的换成新出现的所有副本。如果给出可选的参数计数,则仅替换第一个计数事件。
应用
>>> a = 'h!e!l!l!o! w!o!r!l!d!'
>>> a.replace('!','')
'hello world'
适用于您的情况:
>> 'Breathing 1:-31.145 9:-32.8942 13:-35.8225 2:-35.9872 17:-36.2135 16:-36.6343
12:-36.7487 4:-37.8538 8:-38.6924 7:-39.0389 14:-39.0697 18:-40.0523
3:-40.5393 15:-40.5825 5:-41.6323 11:-45.2976 10:-53.3063
6:-231.617'.replace(':-',' ').split(' ')
['Breathing', '1', '31.145', '9', '32.8942', '13', '35.8225', '2',
'35.9872', '17', '36.2135', '16', '36.6343', '12', '36.7487', '4', '37.8538',
'8', '38.6924', '7', '39.0389', '14', '39.0697', '18', '40.0523', '3',
'40.5393', '15', '40.5825', '5', '41.6323', '11', '45.2976',
'10', '53.3063', '6', '231.617']
所有的定义是从手动
你想要的数组内容是什么?你确定你不想要' - '?数据结构的重要性是什么? –
@KarlKnechtel我相信我不想要''''。 'array [0] ==呼吸,数组[1] == 1,数组[2] == 31.145'等等。 –
你试过正则表达式吗? –