join()
If split()
divides the string into elements, join()
unites list elements together and creates a string from them:
l = ['Hi', 'I', 'am', 'Python', '3', '10']
print('.'.join(l)) # Hi.I.am.Python.3.10
print(' '.join(l)) # Hi I am Python 3 10
print('*-*'.join(l)) # Hi*-*I*-*am*-*Python*-*3*-*10
print('\n'.join(l)) # Hi
# I
# am
# Python
# 3
# 10
Challenge
Given 5 names in the input, print them separated by a -->
.
The input contains 5 names each on a separate line.
The output should contain a single line - all 5 names separated by -->
.
Input | Output |
---|---|
Anna Simon Lily Bob David | Anna-->Simon-->Lily-->Bob-->David |
Constraints
Time limit: 2 seconds
Memory limit: 512 MB
Output limit: 1 MB