anil maran wrote: > the max function, it returns the maximum value in the > list rather than the index associated with that value. > > How do I return the index?
l.index(max(l)) will give you the index of the first occurrance of the maximum. m = max(l) [ i for i,v in enumerate(l) if v==m ] will give you a list of all indices where the max occurs. (Putting the 'max(l)' outside the list comprehension prevents it from being evaluated for each loop element.) Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor