How do I convert all strings in a list of lists to integers?

Here is an example of how you might convert all strings in a list of lists to integers:

original_list = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]

converted_list = [[int(string) for string in sublist] for sublist in original_list]

print(converted_list)
# Output: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

This code uses a list comprehension to iterate over the sublists in original_list, and for each sublist, it uses another list comprehension to iterate over the strings in the sublist and convert them to integers using the int() function. The result is stored in a new list, converted_list.

Watch a course Python - The Practical Guide

Alternatively, you can map this on a single list comprehension as:

converted_list = [[int(s) for s in lst] for lst in original_list]

Keep in mind that this code assumes that all elements in the original list are strings that can be converted to integers. If this is not the case, you may need to add additional code to handle non-convertible elements.