Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to Join list element into a string in python

s = ['KDnuggets', 'is', 'a', 'fantastic', 'resource']

print(' '.join(s))

# Output

# KDnuggets is a fantastic resource


# if you want to join list elements with something other
# than whitespace in between? This thing may be a little bit stranger,
# but also easily accomplished.

s = ['Eleven', 'Mike', 'Dustin', 'Lucas', 'Will']

print(' and '.join(s))

# Ouptut

# Eleven and Mike and Dustin and Lucas and Will
Source by www.kdnuggets.com #
 
PREVIOUS NEXT
Tagged: #How #Join #list #element #string #python
ADD COMMENT
Topic
Name
1+3 =