# 求推荐：多层嵌套list或dict的相关python教程

**URL:** <https://forum.freemdict.com/t/topic/9493>\
**Category:** 技术交流与词典编修\
**Created:** [2021 年11 月 22 日 04:47 UTC](https://forum.freemdict.com/t/topic/9493 "2021-11-22T04:47:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2021 年11 月 22 日 04:47 UTC](https://forum.freemdict.com/t/topic/9493/1 "2021-11-22T04:47:39Z")

</div>

希望设计一个带有多层次导航条的词典，需要用到多层嵌套的list或dict，求相关的python好教程。

现在，我只能通过简单的多次运行来实现，无法整合到一个页面。

![GIF](https://forumcdn.freemdict.com/uploads/default/original/3X/4/1/410189f7a2f0ad1cadc36215006b539ad9b1c4be.gif)

---

<div class="post-metadata">

作者： ![fruition](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/fruition/32/51082_2.png) [@fruition](https://forum.freemdict.com/u/fruition)\
发布日期： [2021 年11 月 22 日 07:23 UTC](https://forum.freemdict.com/t/topic/9493/2 "2021-11-22T07:23:50Z")

</div>

Vim 兄的這個需求似乎有點像是樹狀結構，且又多階的擴展，在下土法煉鋼搞過，蠻麻煩的，若有python 自動生成可以省很多力氣  
那時是用 2 階串 2 階的方法一直串下去，用 mdict tool 那個工具免強的弄出來，在mdict 上用但感覺有點龐大，速度和動作有點跟不上  
階層若多一些動作會更加緩慢，或許當時的處理方式不是很好，過於冗長，以至放棄這個方式

---

<div class="post-metadata">

作者： ![Mandolin](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/mandolin/32/4948_2.png) [@Mandolin](https://forum.freemdict.com/u/Mandolin)\
发布日期： [2021 年11 月 22 日 08:27 UTC](https://forum.freemdict.com/t/topic/9493/3 "2021-11-22T08:27:59Z")

</div>

多层级目录树（可下展），又不换页，得用 JS 吧。

---

<div class="post-metadata">

作者： ![fruition](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/fruition/32/51082_2.png) [@fruition](https://forum.freemdict.com/u/fruition)\
发布日期： [2021 年11 月 22 日 08:31 UTC](https://forum.freemdict.com/t/topic/9493/4 "2021-11-22T08:31:07Z")

</div>

> **[W3Schools online HTML editor](https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_treeview)**
>
> The W3Schools online code editor allows you to edit code and view the result in your browser

> **[W3Schools online HTML editor](https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_treeview2)**
>
> The W3Schools online code editor allows you to edit code and view the result in your browser

W3C 所提供的例子可用只是不算美觀

`<li><a href="entry://Sencha">Sencha</a></li>`

若如此再包覆一層則可直接轉跳，但若是要 Sencha ，再串上詞頭，則結構會變的相當複雜…在下尚未想到好一點的方式

上述的複雜也就是展開且綁定定位在那個結點上 highlight ，而非僅僅是點擊就跳往那個詞頭，如此的結構相當冗長，體積會膨漲的很大，我猜這大概是 vim 兄想要的方式吧！

`<li><a href="entry://Sencha"><mark>Sencha</mark></a></li>`  
然后配上一個詞頭…Sencha …

當然也可以用橫向的方式，只是若某階的詞條太多，則在畫面上顯示會有困擾，且不易一目暸然

用 mdict tool 去2階串2階的方法一直串出來的

 ![2021-11-22_165634](https://forumcdn.freemdict.com/uploads/default/original/3X/8/8/884fc56bb3b36803379496ff8cbc6f14d6360743.png)

==========================================================  
直式的樹狀結構感覺上似乎來的清爽一些，但因沒有再展開的詞條上或項目上 highlight 似乎也是不足的缺憾

![2021-11-22_165907](https://forumcdn.freemdict.com/uploads/default/original/3X/f/0/f03bae20dd040dcd51ad29cbbf7246661ae3f479.png)

---

<div class="post-metadata">

作者： ![Vim](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/vim/32/8408_2.png) [@Vim](https://forum.freemdict.com/u/Vim)\
发布日期： [2021 年12 月 1 日 06:48 UTC](https://forum.freemdict.com/t/topic/9493/5 "2021-12-01T06:48:19Z")

</div>

已经自行解决了。

> [@Longman Lexicon of Contemporary English](https://forum.freemdict.com/t/topic/9670):
>
> 《朗文多功能分类词典》 针对有多层级目录的书籍，专门设计了如下导航系统。感觉比之前大多图片词典在顶部突兀的显示一堆导航链接的整体感官统一性要更好些，适用于语法、用法、分类等类型的图书。 好像可以将以前的很多mdx都用此升级一下。 [Longman Lexicon of Contemporary English]

---

<div class="post-metadata">

作者： ![西北风](https://forumcdn.freemdict.com/letter_avatar_proxy/v4/letter/%E8%A5%BF/a9adbd/32.png) [@西北风](https://forum.freemdict.com/u/%E8%A5%BF%E5%8C%97%E9%A3%8E)\
发布日期： [2021 年12 月 1 日 07:58 UTC](https://forum.freemdict.com/t/topic/9493/6 "2021-12-01T07:58:04Z")

</div>

Roget’s 6th 这部可以分享一下吗？

---

<div class="post-metadata">

作者： ![fruition](https://forumcdn.freemdict.com/user_avatar/forum.freemdict.com/fruition/32/51082_2.png) [@fruition](https://forum.freemdict.com/u/fruition)\
发布日期： [2021 年12 月 1 日 08:18 UTC](https://forum.freemdict.com/t/topic/9493/7 "2021-12-01T08:18:02Z")

</div>

那個作的不是很好啦！哈！哈！
