#!/usr/bin/env python
#encoding=utf8
list=range(1,15)
print list
def show(number,list):
try:
idx=list.index(number)
print idx
except:
return list[:5]
a=idx-2
b=idx+2
start,end=None,None
if a>=0:
start=a
else:
b=abs(a)+b
start=0
if b<=(len(list)-1):
end=b
else:
val=a-(b-(len(list)-1))
if val<0:
start=0
else:
start=val
end=len(list)-1
return list[start:end+1]
print show(19,list)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
[1, 2, 3, 4, 5]
![](http://img.zemanta.com/pixy.gif?x-id=a9282ed0-5e5b-8a5d-8589-e41d1480b430)