📜  python 列表列表中的元素数量 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:32.745000             🧑  作者: Mango

代码示例1
# Basic syntax:
# Using list comprehension:
sum([len(elem) for elem in list_of_lists])

# Example usage:
# Say you want to count the number of elements in a nested list like:
nested_list = [ [1, 2, 3, 45, 6, 7],
                [22, 33, 44, 55],
                [11, 13, 14, 15] ]

sum([len(elem) for elem in nested_list])
--> 14