My code iterates over a set and print actor’s names:
JavaScript
x
3
1
for actor in actorsByMovies():
2
print actor+",",
3
The result looks like:
JavaScript
1
2
1
Brad Pitt, George Clooney,
2
But I want it to detect the last element so that it won’t print the last comma. The result should be instead:
JavaScript
1
2
1
Brad Pitt, George Clooney
2
How can I do that?
Advertisement
Answer
JavaScript
1
2
1
print(', '.join(actorsByMovies()))
2