Discuss / Python / 列表推导方式

列表推导方式

Topic source

抑郁胖子

#1 Created at ... [Delete] [Delete and Lock User]
def get_score_in(low, high):
    try:
        conn = sqlite3.connect(db_file)
        cursor = conn.cursor()
        cursor.execute('select * from user where score >= ? and score <= ?', (low, high))
        values = cursor.fetchall() 
    finally:
        cursor.close()
        conn.commit()
        conn.close()
    return [i[1] for i in sorted(values, key=lambda x: x[2])]

  • 1

Reply