多級評論演算法

2021-08-15 16:47:08 字數 1289 閱讀 3557

comment_list=models.comment.objects.filter(news_id=new_id)

ret=# 最終拿到的資料

comment_list_dict={}# 構建的中間字典

forrowincomment_list:# 通過查到的資料中的id作為key,每一行資料作為value生成乙個字典

row.update()# 構建乙個鍵children對應乙個空列表

comment_list_dict[row["id"]]=row# 將id作為鍵,當前行作為值存到該字典中

foritemincomment_list:# 遍歷一遍取到的資料列表

parrent_row=comment_list_dict.get(item["parent_id"])# 拿到當前行對應的父親的位址

ifnotparrent_row:# 如果父親是none,則直接進入ret中

else:

parrent_row["children"# 重點在這一行,用到了上面提到的第乙個知識點

print(ret)

多級評論資料庫設計

以下所有表述均基於mysql5.6 表設計如下 img 查詢如下 select group concat puid group concat content from a group by uid order by createtime asc,sort asc 結果如下 img 設計及sql語句分...

多級佇列反饋排程演算法

include include typedef struct processnode 程序節點資訊 pcb typedef struct queue 多級就緒佇列節點資訊 readyqueue pcb running null,finished null 定義三個佇列,就緒佇列,執行佇列和完成佇列 ...

多級反饋佇列排程演算法

多級反饋佇列排程演算法是一種cpu處理機排程演算法,unix作業系統採取的便是這種排程演算法。多級反饋佇列排程演算法即能使高優先順序的作業得到響應又能使短作業 程序 迅速完成。對比一下fcfs與高優先響應比排程演算法的缺陷 多級 假設為n級 反饋佇列排程演算法可以如下原理 1 設有n個佇列 q1,q...