Skip to main content
 首页 » 编程设计

python之每个嵌套列表中的元素数

2025年05月04日34pander-it

<分区>

我有一个嵌套列表: [[A,B,A,A],[C,C,B,B],[A,C,B,B]].....等等

我需要在每个嵌套列表中打印 A、B 和 C 的数量。并且还打印每个嵌套列表中的元素总数:

For first nested list: 
A = 3 
B = 1 
#Should not print C! 
total = 4 
 
For second nested list: 
C = 2 
B = 2 
#Should not print A! 
total = 4 
 
... 
... 
... 
so on 

谁能告诉我如何用 python 编写代码?