here2share

# isinstance.py

Oct 2nd, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. # isinstance.py
  2.  
  3. def minmax(mylist, typ):
  4.     """return min/max of mixed list mylist for items of type typ"""
  5.     temp = [x for x in mylist if isinstance(x, typ)]
  6.     return min(temp), max(temp)
  7.  
  8. # minmax() test ...
  9. mixed_list = [100, 'Dave', 12, 'Mary', 7, 'Zoe', 9, 700, 777, 'Peter', 123456789]
  10. print mixed_list
  11.  
  12. print "The min and max of the integers are:"
  13. mn, mx = minmax(mixed_list, int)
  14. print "minimum = %s  maximum = %s" % (mn, mx)
  15.  
  16. print "The min and max of the strings are:"
  17. mn, mx = minmax(mixed_list, str)
  18. print "minimum = %s  maximum = %s" % (mn, mx)
Add Comment
Please, Sign In to add comment