Discuss / Python / 作业

作业

Topic source

大晨紫Zzz

#1 Created at ... [Delete] [Delete and Lock User]
def get_score_in(low, high):
    sql_conn = sqlite3.connect(db_file)
    sql_cursor = sql_conn.cursor()
    try:
        sql_cursor.execute('select name, score from user where score between ? and ?', (low, high))
        data = sorted(sql_cursor.fetchall(), key=lambda x: x[1])
        return [ name[0] for name in data ]
    finally:
        sql_cursor.close()
        sql_conn.close()

这里可以用SQL直接排序,或者用Python来进行排序。 提供一个Python的排序方式

前面的知识记得真清楚 我都快忘了sorted这函数了


  • 1

Reply