I want to add “…” after every odd index in my list (or after every second word), but I can’t quite figure out how to do it.
Advertisement
Answer
you can use something like that:
JavaScript
x
9
1
sentence = input().split()
2
ans = []
3
for i in range(len(sentence)):
4
if i%2:
5
ans.append(sentence[i]+'...')
6
else:
7
ans.append(sentence[i])
8
print(' '.join(ans))
9