2011-12-30 70 views
3

我看着Flask那些天,他們的用戶指南,我發現一個Python代碼片段如下我在哪裏可以學習這個Python括號運算符?

@app.route('/') 
def show_entries(): 
    cur = g.db.execute('select title, text from entries order by id desc') 
    entries = [dict(title=row[0], text=row[1]) for row in cur.fetchall()] 
    return render_template('show_entries.html', entries=entries) 

這裏

entries = [dict(title=row[0], text=row[1]) for row in cur.fetchall()] 

創建一個從數據庫條目列表。這是我第一次知道在括號內生成一個帶有循環的列表。

任何人都可以幫我指出哪裏可以找到官方介紹。對於這樣的語法?它僅僅限於列表而不是元組或其他任何東西?

很多謝謝。 S.

+0

列表理解...牛逼這裏有很多關於這個問題的問題 – JBernardo 2011-12-30 15:16:08

+2

我是唯一一個認爲這個問題的答案相當有趣的人嗎? – 2011-12-30 15:17:48

+0

感謝所有@! – zyzyis 2012-03-27 09:26:59

回答

相關問題