I want my Python function to split a sentence (input) and store each word in a list. My current code splits the sentence, but does not store the words as a list. How do I do
shlex has a .split() function. It differs from str.split() in that it does not preserve quotes and treats a quoted phrase as a single word:
str.split()
>>> import shlex >>> shlex.split("sudo echo 'foo && bar'") ['sudo', 'echo', 'foo && bar']