Advertisement
vivaladiva

Untitled

Oct 27th, 2020
663
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. # Returns all the values in given list,
  2. # which are between mn and mx.
  3. def values_between(lst, mn, mx):
  4.     result = []
  5.  
  6.     # Iterate through the list
  7.     for i in lst:
  8.         # If current number is smaller than mx AND larger than mn,
  9.         # append it to the result list.
  10.         if mn < i < mx:
  11.             result.append(i)
  12.            
  13.     return result
  14.  
  15.  
  16. # Tests
  17.  
  18. # With list of integers
  19. print(values_between([1, 15, 4, 8, 10, 32, 69], 3, 10))
  20.  
  21. # With list of floats
  22. print(values_between([1.2, 5.06, 3.5, 1.1, 4.0, 2.9874, 3.33], 1.15, 3.6))
  23.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement