Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get max length of multi-dimension tuple

My tuple looks something like this(for a particular set of generated value)

tTrains = [ (3, ), (1, 3), (6, 8), (4, 6, 8, 9), (2, 4) ]

Now, what I need to find is the length of longest tuple inside this tuple/list. I can always use a for loop, iterate over all the sub-tuples and do it. But I want to ask if there's a predefined function for the same.

Current Usage

This is what I am going to use as of now

max = 0
for i in range( len(tTrains) ):
  if iMax < len( i ):
    iMax = len( i )
like image 571
hjpotter92 Avatar asked Apr 07 '12 21:04

hjpotter92


1 Answers

tup=[ (3, ), (1, 3), (6, 8), (4, 6, 8, 9), (2, 4) ]
max(map(len,tup))

result:

4
like image 95
Max Li Avatar answered Oct 19 '22 09:10

Max Li