user1642619
user1642619

Reputation:

Adding all lengths of sublists

I can print out the length of maximum length of the sublist with this below

print(len(max(list, key=len)))

Is there a simple way of finding all the length of sublists? For instance, if the sublists have

[1, 2, 3, 4, 5, 6, 7], [2] 

I want to output

8

And if sublists have

[1, 2, 3, 4, 5, 6, 7], [2], [3]

then I want to output

9

Upvotes: 2

Views: 864

Answers (1)

jamylak
jamylak

Reputation: 133764

print(sum(map(len, sublists)))

Upvotes: 2

Related Questions