The lists in Python can handle different type of datatypes in it. The manipulation of such lists is complicated. Let’s say we have a problem in which we need to find the min/max integer value in which the list can contain string as a data type i.e heterogenous. Let’s discuss certain ways in which this can be performed.
Method #1 : Using list comprehension +
min()/max() + isinstance()
This particular problem can be solved by filtering our search of min/max using the isinstance method, we can filter out the integer value and then can use min/max function to get required min/max value.
The original list is : [3, 'computer', 5, 'geeks', 6, 7] The minimum value in list is : 3
Method #2 : Using
lambda + key + max()/min() + isinstance()
The above problem can also be solved using the lambda function as a key in the min()/max() along with the isinstance method which performs the task of checking for integer values.
The original list is : [3, 'computer', 5, 'geeks', 6, 7] The maximum value in list is : 7
- Python | Find maximum length sub-list in a nested list
- Find size of a list in Python
- Python | Find all triplets in a list with given sum
- Find average of a list in python
- Python | Find closest number to k in given list
- Python | Find missing elements in List
- Python | Find k longest words in given list
- Python program to find sum of elements in list
- Python | Find indices with None values in given list
- Python program to find Cumulative sum of a list
- Python | Ways to find indices of value in list
- Python | Find all elements count in list
- Python | Find Mean of a List of Numpy Array
- Python | Find most frequent element in a list
- Python | Ways to find length of list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.