How to join elements at the beginning and end of the list

Ganesh Pal ganesh1pal at gmail.com
Tue Oct 31 10:51:25 EDT 2017


How to join each elements with a delimiter at (1) beginning and end of the
list and (2) connecting all elements  of the list

Example :

>>> value_list =  [1, 2, 3, 4, 56, 's']   I want this to be converted in
this  from '||1||2||3||4||56||s||'

Here is my solution

>>> values = '||' + '||'.join(map(str, value_list)) + '||'
>>> values

'||1||2||3||4||56||s||'


Iam joining the elements at the beginning and end of the list using '+'
operator any other solution, this is not looking neater


I am a Linux user using python 2.7


Regards,
Ganesh



More information about the Python-list mailing list