- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 – Convert Integer Matrix to String Matrix
When it is required to convert an integer matrix to a string matrix, a list comprehension is used.
Example
Below is a demonstration of the same −
my_list = [[14, 25, 17], [40, 28, 13], [59, 44, 66], [29, 33, 16]] print("The list is :") print(my_list) my_result = [[str(element) for element in index]for index in my_list] print("The reuslt is :") print(my_result)
Output
The list is : [[14, 25, 17], [40, 28, 13], [59, 44, 66], [29, 33, 16]] The reuslt is : [['14', '25', '17'], ['40', '28', '13'], ['59', '44', '66'], ['29', '33', '16']]
Explanation
A list is defined and displayed on the console.
A list comprehension is used to iterate over the list, and every element is converted to string and is stored in a list.
This result is assigned to a variable.
This is the output that is displayed on the console.
Advertisements
To Continue Learning Please Login
Login with Google