搜尋此網誌

2012年11月20日 星期二

python 將 for的結果存到list去


一般會這樣寫:

entries_list = []
 for row in entries.find():
    entries_list.append(row)

但是有更省力的寫法:
   
entries_list = [row for row in entries.find()]

贊!
參考 python 2.7.3 tutorial 文件: 5.1.4. List Comprehensions

沒有留言: