I need to print the lists which have minimum and maximum number of 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 the lists with a minimum and maximum lengths. How can I do it?
Output could be something like:
total_list[0] and total_list[2]
max
and min
function in python accepts a key
argument that will find the max of an iterable based on what defined as a key. so, try this:
max(total_list, key=len)
then you can use total_list.index
to find those indexes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With