title: slicing a list based on values
body: <p>I have a sorted list (without duplicates) in python, like so,</p>
  
  <pre><code>l = [1, 3, 5, 8, 9, 11, 13, 17]
  </code></pre>
  
  <p>I would like a take a slice of this based on the list values. So if the value of interest is say, 5. Then I want to locate this value in the list and get 3 values before it in the list.</p>
  
  <p>I can get to my objective with the following function</p>
  
  <pre><code>def f(k):
      if k in l:
          i = l.index(k)
          return (l[i-2:i+1])
      else:
          pass
  
  
  print (f(5))
  
  [1, 3, 5]
  
  
  print (f(13))
  
  [9, 11, 13]
  </code></pre>
  
  <p>However, I have two problems. I do not know what I should do if the value of interest is not a list member. f(6) should also return [1,3,5]. I don't know how to locate 6 in this list</p>
  
  <p>Is there some 'pythonic' way to do this</p>