【发布时间】:2020-02-04 06:22:42
【问题描述】:
我有一个字符串列表,我想将每个字符串拆分为一个浮点数。如果字符串中没有浮点数,我想将它拆分为一个数字。 它应该只拆分一次并返回它之前和之后的所有内容,用逗号分隔。
输入字符串:
['Naproxen 500 Active ingredient Ph Eur',
'Croscarmellose sodium 22.0 mg Disintegrant Ph Eur',
'Povidone K90 11.0 Binder 56 Ph Eur',
'Water, purifieda',
'Silica, colloidal anhydrous 2.62 Glidant Ph Eur',
'Magnesium stearate 1.38 Lubricant Ph Eur']
预期输出:
['Naproxen', '500', 'Active ingredient Ph Eur',
'Croscarmellose sodium', '22.0 mg', 'Disintegrant Ph Eur',
'Povidone K90', '11.0', 'Binder Ph Eur',
'Water, purified',
'Silica, colloidal anhydrous', '2.62', 'Glidant Ph Eur',
'Magnesium stearate', '1.38', 'Lubricant Ph Eur']
【问题讨论】:
-
'Povidone K90', '11.0', 'Binder Ph Eur',根据您的描述,拆分似乎不正确 -
@CoderCharmander 重新阅读问题。这并不是要求对空格进行简单的拆分。
标签: python regex string split pattern-matching