python 多級處理

2022-05-10 07:00:32 字數 1406 閱讀 4878

comment_list =[,,

,,

,]comment_dict ={}

for row in

comment_list:

row[

'child

'] =

comment_dict[row['id

']] =row

#a = [1,2,3]

#b = a

#b 等於的是a列表的記憶體位址 , 所有改變b裡面的值a裡面也會跟著變化

#字典也是

for row in

comment_list:

if row['

reply_id']:

reply_id = row['

reply_id']

comment_dict[reply_id][

'child

'commen_reuslt ={}

#把根資料取出來

for k,v in

comment_dict.items():

if v['

reply_id

'] ==none:

commen_reuslt[k] = v

print(len(commen_reuslt), commen_reuslt)

列印結果:

2 ,],'

reply_id

': 1, '

content

': '

寫的真好

', '

news_id

': 1, '

user_id

': 12, '

id': 3}],

'reply_id

': none, '

content

': '

寫的什麼玩意呀

', '

news_id

': 1, '

user_id

': 10, '

id': 1},

5: }

前端頁面生成:

def

create_child_html(child_comment):

prve = """

"""return prve +end

defcreate_html(comment_reuslt):

prve = """

"""return prve + end

前端樣式(左邊距):

.comment > .content

後台管理,在django中如果有後台,前端、後台要分別建立專案

- 簡單選單(適用於固定個數選單)

- 動態選單

用到根選單和子選單,就要用到多級處理

python 多級選單 python多級選單

該樓層疑似違規已被系統摺疊 隱藏此樓檢視此樓 dic china 直轄市 北京市 東城區 西城區 崇文區 宣武區 朝陽區 海淀區 豐台區 石景山區 門頭溝區 房山區 通州區 順義區 昌平區 大興區 懷柔區 平谷區 延慶縣 密雲縣 省 浙江省 杭州市 拱墅區 上城區 下城區 江乾區 西湖區 濱江區 蕭...

python 多級選單(多級登入)

1 簡單繁多版 未優化之前 author liangchen date 2019 8 15 menu 東湖區 吉安 吉水 上海 嘉定新城 徐匯 徐家匯站 廣東 白石山 惠州 人字岡 flag true while true and flag for i in menu print i select1...

python練習 多級選單

基本功能 1.可依次選擇進入各子選單 2.可從任意一層往回退到上一層 3.可從任意一層退出程式 使用說明 通過輸入進入各子選單,輸入 u 返回上一級選單,輸入 q 退出程式。menu 網易 google 中關村 汽車之家 youku 上地 昌平 北航 天通苑 回龍觀 朝陽 東城 上海 閘北 浦東 山...