Discuss / Python / map好用哦

map好用哦

Topic source

xiongdezhi

#1 Created at ... [Delete] [Delete and Lock User]
def get_score_in(low, high):
    ' 返回指定分数区间的名字,按分数从低到高排序 '
    with sqlite3.connect(db_file) as conn:
        cursor = conn.cursor()
        cursor.execute('select name from user where score between ? and ?', (low, high))
        values = cursor.fetchall()

    return map(lambda x: x[0], values)

Python 3 中map 返回的不是列表,而是迭代器, So

return list(map(lambda x: x[0], values))

  • 1

Reply