You could use enumerate
:
d = {}
for i, v in enumerate(input().split()):
d[i] = v
Or simply:
d = dict(enumerate(input().split()))
But why do that? use a list
...
Since your keys are simply (ordered!) integers, using a dict seems an overkill as to access integer-indexed values from a list is also O(1)
. For example, let's look at a small comparison with the 2 versions:
l = input().split()
d = dict(enumerate(l))
We have:
>>> print(l)
['apple', 'orange', 'banana']
>>> print(d)
{0: 'apple', 1: 'orange', 2: 'banana'}
Now let's see how we will grab values:
>>> l[0]
'apple'
>>> d[0]
'apple'
>>> l[2]
'banana'
>>> d[2]
'banana'
Dictionaries have a small memory overhead and so for this case using a dictionary doesn't give any advantage.