- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- 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.
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)
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']]
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.
Kickstart Your Career
Get certified by completing the courseGet Started