1 2 3 4
import re x = [ [1, 2], 1, 1, [2, 1, [1, 2]] ] nums = [int(i) for i in re.findall(r'\d+', str(x))] print(nums.count(1))
1
5