# Python – Convert Integer Matrix to String Matrix

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

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.

Updated on 08-Sep-2021 10:33:42