Discuss / Python / 作业

作业

Topic source

Junhong1994

#1 Created at ... [Delete] [Delete and Lock User]

看了你们的答案才知道原来还可以用'order by score'排序。

def get_score_in(low,high):
    conn = sqlite3.connect('test.db')
    cursor = conn.cursor()
    try:
        cursor.execute('select * from user where ?<=score and score<=?', (low,high))
        values = cursor.fetchall()
    finally:
        cursor.close()
        conn.close()
    #排序
    values.sort(key = lambda x:x[2])    
    return [i[1] for i in values]

  • 1

Reply