- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Convert Matrix to String
When it is required to convert a matrix into a string, a simple list comprehension along with the ‘join’ method can be used.
Below is a demonstration of the same
my_list = [[1, 23, "python"], [1, "is", 24], ["fun", 97, 5]] print("The list is :") print(my_list) in_delete, out_delete = ",", " " my_result = out_delete.join([in_delete.join([str(element) for element in sub]) for sub in my_list]) print("The output string is :") print(my_result)
The list is : [[1, 23, 'python'], [1, 'is', 24], ['fun', 97, 5]] The output string is : 1,23,python 1,is,24 fun,97,5
A list of list is defined and is displayed on the console.
Two variables with symbols are defined.
A list comprehension is used to iterate through the elements in the list.
The elements are joined based on a specific condition.
This is assigned to a variable.
This variable is displayed as output on the console.
- Python - To Convert Matrix to String
- Python – Convert Integer Matrix to String Matrix
- Python Program – Convert String to matrix having K characters per row
- Python program to Convert Matrix to Dictionary Value List
- Python program to convert a list to string
- Python program to convert hex string to decimal
- Python – Convert String to matrix having K characters per row
- Convert a list to string in Python program
- Program to convert given Matrix to a Diagonal Matrix in C++
- Java Program to Convert Character to String
- Java Program to Convert String to Date
- Java Program to Convert InputStream to String
- Java Program to Convert OutputStream to String
- C# Program to Convert Integer to String
- C# program to convert string to long