I'm just a new in python and I need to print the lists which has minimum and maximum items in a list.
For example if i have:
total_list = [[1, 2, 3], [1, 2, 3, 4], [1,2,3,4,5]]
I need to return a list with a minimum and maximum length of itself. How can I do it simply in python way?
I try to iterate over it but all I could receive is the only len
of each item in a list
Output must be:
total_list[0] and total_list[2]
Thanks in advance
The usage of
min( iterable, key=len)
(min/max) is easiest. If you like to go through your list yourself, you can do this like so:Output:
Doku:
max
andmin
function in python accepts akey
argument that will find the max of an iterable based on what defined as a key. so, try this:then you can use
total_list.index
to find those indexesOUTPUT: