好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

分页程序,可以作为面试题

分页程序,可以作为面试题

始终使当前页面,尽可能的在中间
#!/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]


查看更多关于分页程序,可以作为面试题的详细内容...

  阅读:41次

上一篇: online gzip test tool

下一篇:currency symobl