Discuss / Python / 2016-7-22作业

2016-7-22作业

Topic source

本来是写了这个的。

def get_score_in(low, high):
    sq=sqlite3.connect(db_file)
    cur=sq.cursor()
    cur.execute(r'select name from user a where a.score>=? and a.score<=? order by score' ,(low,high))
    res=cur.fetchall()
    cur.close()
    sq.close()
    lst=[]
    for elem in res:
        lst.append(elem[0])
    #print(lst)
    return lst

后来看了同学们的代码,他们的return更加pythonic

    return [x[0] for x in res]

  • 1

Reply