在列表的子列表中查找数字并求和

Find digits in the sublists of the list and sum it

我有一个此类格式的深度嵌套列表。

[['A',
  1668034967,
  [[322211651,
    'foo1',
    'foo2',
    'foo3',
    '1528'] # this 'row',
   [241737340,
    'foo1',
    'foo2',
    'foo3',
    '1032']]] # this 'row',
['B',
  1668034968,
  [[173817552,
    'foo1',
    'foo2',
    'foo3',
    '2196']]]]  # this 'row'

我需要总结子列表中所有选定的值(见评论)。 因此,输出将是: 1528 + 1032 + 2196 = 4756

我考虑过 lambda 和列表推导,但是那个列表很深,所以我不知道如何正确使用 lambda。

我这样试过

tests = # the list before in example
[int(x[2][0][4]) for x in tests]
# results in [1528, 2196] however I need [1528, 1032, 2196]

首先,确保您可以 select 嵌套列表中的正确部分:

>>> [v[-1] for sub in mylist for v in sub[-1]]
['1528', '1032', '2196']

然后,将它们相加,如int:

>>> sum([int(v[-1]) for sub in mylist for v in sub[-1]])
4756