Let's assume I have a string
st = "'aaa': '1', 'bbb': '2.3', 'ccc': 'name'"
I want to extract from st the following
['1', '2.3', 'name']
How can I do this?
Thanks
Doing it with ast
module would be best, like jezrael did it. Here is another solution with regex:
import re
st = "'a': '1', 'b': '2.3', 'c': 'name', 'd': 229, 'e': '', 'f': '228', 'g': 12"
print re.findall(r'\'\S+?\':\s*\'?(.*?)\'?(?:,|$)', st)
Output:
['1', '2.3', 'name', '229', '', '228', '12']
Demo on regex101:
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加