Take integer only from a nested list and apply function to it

I am super new at Python and I am facing a problem when converting a nested list to a list of integer only.

I have this type of nested list in which all sub-list contains strings (digit and char)

lists = [['1', '2', '0', 'a', 'b'], ['3', '2', '1'], ['1','5', '5']]

I want to convert the digits to integer, and also put the char in one list. The output that I want is something like this

`new_lists = [[1, 2, 0, 'a', 'b'], [3, 2, 1], [1, 5, 5]]`

What would i do is something like this

for item in lists:
if (in the first list item can be converted to integer):

How the string can be converted to an integer? Or is there any better way to do it? Thanks in advance

Read more here: https://stackoverflow.com/questions/66997738/take-integer-only-from-a-nested-list-and-apply-function-to-it

Content Attribution

This content was originally published by Trojan666 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: