Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # isinstance.py
- def minmax(mylist, typ):
- """return min/max of mixed list mylist for items of type typ"""
- temp = [x for x in mylist if isinstance(x, typ)]
- return min(temp), max(temp)
- # minmax() test ...
- mixed_list = [100, 'Dave', 12, 'Mary', 7, 'Zoe', 9, 700, 777, 'Peter', 123456789]
- print mixed_list
- print "The min and max of the integers are:"
- mn, mx = minmax(mixed_list, int)
- print "minimum = %s maximum = %s" % (mn, mx)
- print "The min and max of the strings are:"
- mn, mx = minmax(mixed_list, str)
- print "minimum = %s maximum = %s" % (mn, mx)
Add Comment
Please, Sign In to add comment