How to connect the contents of a list into a string

How to connect the contents of a list into a string

There was no way to make a character string unexpectedly, so it's rudimentary

l = ['a', 'b', 'c', 'd', 'e']

a = ' '.join(l)
print(a)

Output result

'a b c d e'

** The string to be combined must be (str type). ** ** If the element is a numeric value, it needs to be converted to str type by, for example, map () function.

b = '_'.join(map(str, l))
print(b)

Output result

'1_2_3_4_5'

Recommended Posts

How to connect the contents of a list into a string
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Ubuntu] How to delete the entire contents of a directory
[Python] A program that rotates the contents of the list to the left
How to calculate the volatility of a brand
How to write a list / dictionary type of Python3
How to pass the execution result of a shell command in a list in Python
How to access the contents of a Linux disk on a Mac (but read-only)
How to get a list of files in the same directory with python
How to shuffle a part of a Python list (at random.shuffle)
How to identify the element with the smallest number of characters in a Python list?
How to display a list of installable versions with pyenv
How to get the last (last) value in a list in Python
How to see the contents of the Jupyter notebook ipynb file
How to check in Python if one of the elements of a list is in another list
How to find the scaling factor of a biorthogonal wavelet
Extract the value of dict or list as a string
How to get a list of links from a page from wikipedia
How to quickly count the frequency of appearance of characters from a character string in Python?
How to pass the execution result of a shell command in a list in Python (non-blocking version)
How to determine the existence of a selenium element in Python
[EC2] How to install chrome and the contents of each command
How to check the memory size of a variable in Python
How to check the memory size of a dictionary in Python
[TensorFlow 2] How to check the contents of Tensor in graph mode
How to find the memory address of a Pandas dataframe value
How to output the output result of the Linux man command to a file
How to get the vertex coordinates of a feature in ArcPy
How to extract the desired character string from a line 4 commands
Create a function to get the contents of the database in Go
[NNabla] How to remove the middle tier of a pre-built network
How to check the version of Django
[Python] How to convert a 2D list to a 1D list
[Python] How to invert a character string
String conversion of a list containing numbers
Summary of how to use Python list
How to put the string JSON passed as a parameter into the dictionary when writing Ansible module
[Python] How to put any number of standard inputs in a list
How to compare if the contents of the objects in scipy.sparse.csr_matrix are the same
I want to sort a list in the order of other lists
[NNabla] How to add a quantization layer to the middle layer of a trained model
How to put a line number at the beginning of a CSV file
How to create a wrapper that preserves the signature of the function to wrap
[Introduction to Python] How to write a character string with the format function
How to format a list of dictionaries (or instances) well in Python
How to play a video while watching the number of frames (Mac)
A simple example of how to use ArgumentParser
How to find the area of the Voronoi diagram
How to clear tuples in a list (Python)
How to embed a variable in a python string
Divide the string into the specified number of characters
Make a copy of the list in Python
[Algorithm x Python] How to use the list
A python amateur tries to summarize the list ②
How to copy and paste the contents of a sheet in Google Spreadsheet in JSON format (using Google Colab)
How to mention a user group in slack notification, how to check the id of the user group
How to achieve something like a list of void * (or variant) in Go?
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[NNabla] How to get the output (variable) of the middle layer of a pre-built network
How to count the number of elements in Django and output to a template
A memorandum of how to execute the! Sudo magic command in Jupyter Notebook