Advertisement
OreganoHauch

Maximum function for all numbers in a list

Jan 12th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. # MAXIMUM FUNCTION FOR ALL NUMBERS IN A LIST WITH N ENTRIES
  2.  
  3. num_list = [1, 4, 5, 100, "Text", 3.5, 23]
  4.  
  5. def maxN(list):
  6. # Create a new list which only includes integers and floats from old list:
  7. list_num_only = [k for k in list if isinstance(k, float) or isinstance(k, int)]
  8. # Define the maximum of 2 numbers:
  9. def max(a, b):
  10. return (list_num_only[a] + list_num_only[b] + abs(list_num_only[a] - list_num_only[b])) / 2
  11. max_interim = 0
  12. for i in range(len(list_num_only)-1):
  13. max_interim = max(max(list_num_only[i], list_num_only[i+1]), list_num_only[i+2])
  14. return max_interim
  15.  
  16. print(maxN(num_list))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement