For the easiest solution to your problem, @Chris_Rands already posted it in a comment to your question: .split()
returns a list. You don't have to make a separate one for the result, just enumerate the value returned by the split function:
inputwords = input('What keywords are you looking for?').split()
result = list(enumerate(inputwords))
print(result)
What keywords are you looking for? This is a list of words.
[(0, 'This'), (1, 'is'), (2, 'a'), (3, 'list'), (4, 'of'), (5, 'words.')]
As noted in the other answer, it is a good idea to put a space after your prompt, that way there is separation between it and what the user is typing in:
inputwords = input('What keywords are you looking for? ').split()
Your code will not work with python2 though, where the input()
function is actually running the resulting string through eval()
:
>>> input()
1 + 2 + 3
6
For more information, see this question.
If you want your code to be compatible with both python2 and python3, use this little snippet:
try:
input = raw_input
except NameError:
pass
This will make sure that input
is pointing to the python3 version of the function.