Discuss / Python / 抄了下作业,感觉看的似懂非懂

抄了下作业,感觉看的似懂非懂

Topic source
def get_score_in(low, high):
    ' 返回指定分数区间的名字,按分数从低到高排序 '
    conn = sqlite3.connect(db_file)
    cur = conn.cursor()
    try:
        cur.execute('select * from user where score between ? and ? order by score',(low,high))
        data = cur.fetchall()
        print(data)
        data = sorted(data, key=lambda s: s[2])      # [('id','name','score'),(),()...], 根据score排序
        print(data)
        return list(map(lambda x : x[1], data))
    finally:
        cur.close()
        conn.close()

很棒!


  • 1

Reply