這是我的代碼列表解析,並列出清單列表連接
[temp.append(i.get_hot_post(3)) for i in node_list]
[hot_posts+i.sort(key=sort_by_rate) for i in temp ]
get_hot_posts()返回的3項的列表這樣
return recent_posts[0:amount-1]
這可能是因爲該列表短3個元素,它可能一塌糊塗周圍的事物,但
[temp.append(i.get_hot_post(3)) for i in node_list]
去該命令後,在「臨時」我有名單列表這很好。
但是,當執行
[hot_posts+i.sort(key=sort_by_rate) for i in temp ]
它給這個錯誤
TypeError: can only concatenate list (not "NoneType") to list
下面的回答都不錯,這裏是[列表理解(http://docs.python.org/tutorial/datastructures.html#list文檔-comprehensions) – casper