Если вы не можете получить более чистый, чем вход, я бы рекомендовал использовать регулярное выражение и создавая list
из tuple
с с findall()
:
>>> import re
>>> mystring = '"hello":"noun":"a greeting";"hello":"verb":"the;action;of;greeting"'
>>> result = re.findall(r'"(.+?)":"(.+?)":"(.+?)"', mystring)
>>> for item in result:
... print(*item)
...
hello noun a greeting
hello verb the;action;of;greeting
You может форматировать выход с str.format()
:
>>> for item in result:
... print('{} - {}, {}'.format(*(part.replace(';', ' ') for part in item)))
...
hello - noun, a greeting
hello - verb, the action of greeting
're.split' on' '"[;:]"' '? – cdarke
Что, если это то, что * внутри * цитаты? Кажется, что это требует токенизатора – dwanderson