Discuss / Python / 借机回顾一下之前的知识

借机回顾一下之前的知识

Topic source
def by_score(x):
    return x[2]

def get_score_in(low, high):
    ' 返回指定分数区间的名字,按分数从低到高排序 '
    try:
        conn = sqlite3.connect('test.db')
        cursor = conn.cursor()
        for n in range(low, high + 1):
            cursor.execute('select * from user where score between ? and ?', (low, high))
            values = cursor.fetchall()
    finally:
        cursor.close()
        conn.close()
    # print(values)
    l = list(map(lambda x: x[1], sorted(values, key=by_score)))
    return l

  • 1

Reply