housekeeping stuffed, parse large dictionary

main
onebigear 2 years ago
parent 4305535758
commit a77966fdac

Before

Width:  |  Height:  |  Size: 39 KiB

After

Width:  |  Height:  |  Size: 39 KiB

Before

Width:  |  Height:  |  Size: 8.9 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Before

Width:  |  Height:  |  Size: 418 KiB

After

Width:  |  Height:  |  Size: 418 KiB

Before

Width:  |  Height:  |  Size: 320 KiB

After

Width:  |  Height:  |  Size: 320 KiB

Before

Width:  |  Height:  |  Size: 93 KiB

After

Width:  |  Height:  |  Size: 93 KiB

Before

Width:  |  Height:  |  Size: 196 KiB

After

Width:  |  Height:  |  Size: 196 KiB

Before

Width:  |  Height:  |  Size: 186 KiB

After

Width:  |  Height:  |  Size: 186 KiB

Before

Width:  |  Height:  |  Size: 194 KiB

After

Width:  |  Height:  |  Size: 194 KiB

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 133 KiB

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Before

Width:  |  Height:  |  Size: 134 KiB

After

Width:  |  Height:  |  Size: 134 KiB

Before

Width:  |  Height:  |  Size: 100 KiB

After

Width:  |  Height:  |  Size: 100 KiB

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

Before

Width:  |  Height:  |  Size: 214 KiB

After

Width:  |  Height:  |  Size: 214 KiB

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 204 KiB

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 57 KiB

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before

Width:  |  Height:  |  Size: 136 KiB

After

Width:  |  Height:  |  Size: 136 KiB

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

Before

Width:  |  Height:  |  Size: 185 KiB

After

Width:  |  Height:  |  Size: 185 KiB

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

File diff suppressed because it is too large Load Diff

@ -0,0 +1,303 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# a bonary tree"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#***********************************************************************\n",
"#** a bo-binary tree *\n",
"#** for and inspired by Wang Xiaobo (1952-1997), writer and programmer.*\n",
"#** \"我也自做了词组功能是棵B树我觉得自写的软件自用感觉是最好的。\" *\n",
"#** \"I created a word feature with a binary tree strucutre, *\n",
"#** and I feel best about using a program you created yourself.\" *\n",
"#** read more in archival documentation(Chinese): *\n",
"#** https://blog.csdn.net/weixin_33697898/article/details/93356187 *\n",
"#** *\n",
"#***********************************************************************"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### 思维的乐趣 \n",
"### on discourse \n",
"### quotes from 《我的精神家园》\n",
"谈到思想的乐趣,我就想到我父亲的遭遇。我父亲是一位哲学教授,在五六十年代从事思维史的研究。在老年时,他告诉我自己一生的学术经历,就如一部恐怖电影。每当他企图立论时,总要在大一统的思想体系里找到自己的位置,就如一只老母鸡要在一个大搬家的宅院里找地方孵蛋一样。结果他虽然热爱科学而且很努力,在一生中却没有得到思维的乐趣,之收获了无数的恐慌。他一生的探索,只剩下了一些断壁残垣,收到一本名为《逻辑探索》的书里,在他身后出版。\n",
"\n",
"我在沉默中过了很多年:插队、当工人、当大学生,后来又在大学里任过教。当教师的人保持沉默似不可能,但我教的是技术性的课程,在讲台上只讲技术性的话,下了课我就走人。找我看,不管干什么都可以保持沉默。当然,我还有一个终身爱好,就是写小说。但是写好了不拿去发表,同样也保持了沉默。至于沉默的理由,很是简单。那就是信不过话语圈。从我短短的人生经历看,它是一座声名狼藉的疯人院。当时我怀疑的不是说过亩产三十万斤粮、炸过精神原子弹的那个话语圈,而是一切话语圈子。\n",
"\n",
"还有一些人,因为种种原因,对于话语的世界有某种厌恶之情。我属于这最后一种。作为最后一种人,也有义务谈自己的所见所闻。\n",
"\n",
"王小波1997).《我的精神家园》.北京:文化艺术出版社.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#Create a proof of concept dictionary tree that looks for hong(3) fu(2)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from anytree import Node, RenderTree\n",
"h = Node(\"h\")\n",
"o = Node(\"o\", parent=h)\n",
"n = Node(\"n\", parent=o)\n",
"g = Node(\"g\", parent=n)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Node('/h')\n",
"Node('/h/o/n/g')\n",
"h\n",
"└── o\n",
" └── n\n",
" └── g\n"
]
}
],
"source": [
"#print node\n",
"print(h)\n",
"print(g)\n",
"\n",
"#print tree\n",
"for pre, fill, node in RenderTree(h):\n",
"\tprint(\"%s%s\" %(pre,node.name))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"f\n",
"└── u\n"
]
}
],
"source": [
"f = Node(\"f\")\n",
"u = Node(\"u\", parent = f)\n",
"for pre, fill, node in RenderTree(f):\n",
"\tprint(\"%s%s\" %(pre,node.name))\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"y\n",
"└── e\n"
]
}
],
"source": [
"y = Node(\"y\")\n",
"e = Node(\"e\", parent = y)\n",
"for pre, fill, node in RenderTree(y):\n",
"\tprint(\"%s%s\" %(pre,node.name))"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"b\n",
"└── e\n",
" └── n\n"
]
}
],
"source": [
"b = Node(\"b\")\n",
"e = Node(\"e\", parent = b)\n",
"n = Node(\"n\", parent = e)\n",
"for pre, fill, node in RenderTree(b):\n",
"\tprint(\"%s%s\" %(pre,node.name))"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"def printTree(root):\n",
" for pre, fill, node in RenderTree(root):\n",
" print(\"%s%s\" %(pre,node.name))"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"h\n",
"└── o\n",
" └── n\n",
" └── g\n",
"红\n",
"\n",
"f\n",
"└── u\n",
"拂\n",
"\n",
"y\n",
"└── e\n",
"夜\n",
"\n",
"b\n",
"└── e\n",
" └── n\n",
"奔\n",
"\n"
]
}
],
"source": [
"tree_list = [h,f,y,b]\n",
"红拂夜奔 = [\"红\",\"拂\",\"夜\",\"奔\"]\n",
"counter = 0\n",
"for tree in tree_list:\n",
" printTree(tree)\n",
" print(红拂夜奔[counter])\n",
" counter = counter + 1\n",
" print()"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# an alphabet binary search tree\n",
"import string\n",
"alphabet_s = string.ascii_lowercase\n",
"alphabet_l = list(alphabet_s)\n",
"#print(alphabet_l)\n",
"# add nodes manually, starting from m "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<video src=\"vid/wang_interview.mp4\" controls >\n",
" Your browser does not support the <code>video</code> element.\n",
" </video>"
],
"text/plain": [
"<IPython.core.display.Video object>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import IPython.display \n",
"Video('vid/wang_interview.mp4')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# transcription of wang's interview in Chinese\n",
"# autotranslate that into English for non-Chinese readers"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"数据结构是思维的形状的一种表现方式\n",
"the structure of data may be one representation of the form of thought "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Wang Xiaobo (1952-1997), writer and programmer. <br>\n",
"\"我也自做了词组功能是棵B树我觉得自写的软件自用感觉是最好的。\" <br>\n",
"\"I created a word feature with a binary tree strucutre, and I feel best about using a program you created yourself.\"\n",
"read more in archival documentation(Chinese):<br>\n",
"https://blog.csdn.net/weixin_33697898/article/details/93356187"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

@ -0,0 +1,79 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "666a35e1-435d-4555-8193-9258ff568e21",
"metadata": {},
"outputs": [],
"source": [
"class letterLeaf:\n",
" def __init__(self,question):\n",
" self.yes = None\n",
" self.no = None\n",
" self.question = question\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "254b714a-2504-4cc0-9a78-21d406ddbb2f",
"metadata": {},
"outputs": [],
"source": [
"# tree traversals, here to print stuff \n",
"def inorder(treeName):\n",
" if treeName:\n",
" inorder(treeName.yes)\n",
" print(treeName.question)\n",
" inorder(treeName.no)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8512457-7944-4604-92c7-29f90ab6c3db",
"metadata": {},
"outputs": [],
"source": [
"# interactive user input utility \n",
"def saysYes(ques):\n",
" while True:\n",
" ans = input(ques)\n",
" ans = ans[0:1].lower()\n",
" if ans == 'y': return True\n",
" else : return False"
]
},
{
"cell_type": "markdown",
"id": "8415d1d2-211a-4e82-b331-85527e8c1510",
"metadata": {},
"source": [
"reference\n",
"https://web.stonehill.edu/compsci/CS211/Assignmenta%202015/TreeAssignment.pdf"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,750 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "9da34557-037a-436f-bbaa-d332057cbe18",
"metadata": {},
"source": [
"# a fruit tree with a variety of fruits hanging, each enclosed in a picture frame. "
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "01acaa97-796a-4e34-9ee3-a46e71493d9d",
"metadata": {},
"outputs": [],
"source": [
"fruit_list = [\"apricot\",\"blood_orange\",\"currant\",\"durian\",\"egg_fruit\",\"fig\",\"guava\",\n",
" \"hawthorne\",\"jujube\",\"kiwi\",\"lychee\",\"mandarin\",\"nectarine\",\"olive\",\"persimmon\",\"quandong\",\"rambutan\",\"star_fruit\",\n",
" \"tangor\",\"ugli_fruit\",\"vanilla\",\"water_chestnut\",\"ximenia\",\"yuzu\",\"zhe\"]\n",
"# additionally: longan yumberry sugarcane "
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "08ab8673-9b5c-4bd0-9fac-72796e831b94",
"metadata": {},
"outputs": [],
"source": [
"# build the fruit motley tree with extra utilities than the letter tree"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "9c7187e4-0c49-4908-a169-775e6e475f94",
"metadata": {},
"outputs": [],
"source": [
"class letterLeaf:\n",
" def __init__(self,wordFruit,path):\n",
" self.leftAlphabet = None\n",
" self.rightAlphabet = None\n",
" self.wordFruit = wordFruit\n",
" # try using a list structure to contain the words in this node? \n",
" self.path = path"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "11dbf280-6c61-4020-bfe7-e85a723697db",
"metadata": {},
"outputs": [],
"source": [
"# printing tree utility \n",
"# the display cannot indent?\n",
"from IPython.display import Image\n",
"COUNT = [10]\n",
"\n",
"# print a flat lying tree\n",
"# speculation this is a recursion that prints the right leaf until there is nothing left\n",
"def print2DUtil_flat(root, space) :\n",
" # Base case\n",
" if (root == None) :\n",
" return\n",
" # Increase distance between levels\n",
" space += COUNT[0]\n",
" print2DUtil_flat(root.rightAlphabet, space)\n",
" print()\n",
" \n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" url_tree = root.path\n",
" i = Image(url= url_tree, width=30, height=30)\n",
" display(i)\n",
"\n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" print(root.wordFruit)\n",
" print2DUtil_flat(root.leftAlphabet, space)\n",
"\n",
" # Wrapper over print2DUtil()\n",
"def print2D(root) :\n",
" #Pass initial space count as 0\n",
" print(\"here is a tree that's laying on the ground: \")\n",
" # import image module\n",
" # get the image\n",
" print2DUtil_flat(root, 0)\n"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "d0bcd376-491e-48e9-8bd9-e10d91346d7f",
"metadata": {},
"outputs": [],
"source": [
"def urljoin(wordFruit):\n",
" url = \"images/pic_tree_fruit_img/\" + wordFruit + \".png\"\n",
" return url "
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "7a12a00f-f7b0-4234-a06c-54c6f3d1daf1",
"metadata": {},
"outputs": [],
"source": [
"def insertLeaf(root,wordFruit):\n",
" #create new leaf \n",
" url = urljoin(wordFruit)\n",
" newleaf = letterLeaf(wordFruit,url)\n",
" #print(\"creating leaf with word = {} url = {}\".format(newleaf.wordFruit,newleaf.path))\n",
"\n",
" # python pointer implementation\n",
" # a root pointer \n",
" x = root\n",
" # pointer y maintains the trailing\n",
" # pointer of x\n",
" # Pointer to start traversing from root\n",
" # and traverses downward path to search\n",
" # where the new node to be inserted\n",
" x = root\n",
"\n",
" # Pointer y maintains the trailing\n",
" # pointer of x\n",
" y = None\n",
"\n",
" while (x != None):\n",
" y = x\n",
" if (wordFruit < x.wordFruit):\n",
" x = x.leftAlphabet\n",
" else:\n",
" x = x.rightAlphabet\n",
" \n",
" # If the root is None i.e the tree is\n",
" # empty. The new node is the root node\n",
" if (y == None):\n",
" y = newleaf\n",
"\n",
" # If the new key is less then the leaf node key\n",
" # Assign the new node to be its left child\n",
" elif (wordFruit < y.wordFruit):\n",
" y.leftAlphabet = newleaf\n",
"\n",
" # else assign the new node its\n",
" # right child\n",
" else:\n",
" y.rightAlphabet = newleaf\n",
"\n",
" # Returns the pointer where the\n",
" # new node is inserted\n",
" return y\n",
"\n",
"\n",
"# A utility function to do inorder\n",
"# traversal of BST"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "dc2230e9-0831-4e3c-93b8-c96d20fd0525",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"here is a tree that's laying on the ground: \n",
"\n"
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/zhe.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"zhe\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/yuzu.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" yuzu\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/ximenia.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" ximenia\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/water_chestnut.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" water_chestnut\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/vanilla.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" vanilla\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/ugli_fruit.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" ugli_fruit\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/tangor.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" tangor\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/star_fruit.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" star_fruit\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/rambutan.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" rambutan\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/quandong.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" quandong\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/persimmon.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" persimmon\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/olive.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" olive\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/nectarine.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" nectarine\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/mandarin.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" mandarin\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/lychee.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" lychee\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/kiwi.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" kiwi\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/jujube.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" jujube\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/hawthorne.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" hawthorne\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/guava.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" guava\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/fig.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" fig\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/egg_fruit.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" egg_fruit\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/durian.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" durian\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/currant.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" currant\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/blood_orange.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" blood_orange\n",
"\n",
" "
]
},
{
"data": {
"text/html": [
"<img src=\"images/pic_tree_fruit_img/apricot.png\" width=\"30\" height=\"30\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
" apricot\n"
]
}
],
"source": [
"# same deal, insert everything in the list until it's empty \n",
"import random\n",
"\n",
"root = None\n",
"# pick a random letter in the alphabet\n",
"random_fruit = random.choice(fruit_list)\n",
"#print(random_letter)\n",
"#insert it into the tree, insert the first one \n",
"root = insertLeaf(root, random_fruit)\n",
"# remove that letter from list\n",
"fruit_list.remove(random_fruit)\n",
"#print(fruit_list)\n",
"len_list = (len(fruit_list))\n",
"#print(len_list)\n",
"while len_list > 0:\n",
" random_fruit = random.choice(fruit_list)\n",
" insertLeaf(root,random_fruit)\n",
" fruit_list.remove(random_fruit)\n",
" #print(\"inserting and removing letter {} \".format(random_letter))\n",
" len_list -= 1\n",
"# keep inserting until the list is empty \n",
"# print tree \n",
"print2D(root)\n",
"# can try multiple times for different tree configurations\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,405 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "4708c5dc-a1e8-42e2-8702-ecea9513d54b",
"metadata": {},
"source": [
"# a binary tree of leaves of letters"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "906fc548-a2a5-411b-ad60-9e93e88bf7f5",
"metadata": {},
"outputs": [],
"source": [
"# http://syllabus.cs.manchester.ac.uk/ugt/2021/COMP26912/lab/ex5.html\n",
"# https://web.stanford.edu/class/archive/cs/cs106x/cs106x.1174/assn/twentyOneQuestions.html\n",
"# https://www.openbookproject.net/py4fun/animal/animal.html"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "578e93f8-e04f-4b01-a482-ebc78cf2c103",
"metadata": {},
"outputs": [],
"source": [
"# each leaf stores a letter to be asked\n",
"class letterLeaf:\n",
" def __init__(self,letter):\n",
" self.leftAlphabet = None\n",
" self.rightAlphabet = None\n",
" self.letter = letter\n",
" # try using a list structure to contain the words in this node? \n",
" self.words = []"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "fa8e3d45-ea21-47e1-9a5a-256e5e7ebed1",
"metadata": {},
"outputs": [],
"source": [
"# tree traversals, here to print stuff \n",
"def inorder(treeName):\n",
" if treeName:\n",
" inorder(treeName.leftAlphabet)\n",
" print(treeName.letter)\n",
" inorder(treeName.rightAlphabet)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "0c75f820-46c4-46af-b5d9-b837cb055b55",
"metadata": {},
"outputs": [],
"source": [
"# printing tree utility \n",
"# this segment is modified from Shubham Singh(SHUBHAMSINGH10)'s contribution \n",
"\n",
"# spacer\n",
"COUNT = [10]\n",
"\n",
"# print a flat lying tree\n",
"# speculation this is a recursion that prints the right leaf until there is nothing left\n",
"def print2DUtil_flat(root, space) :\n",
" # Base case\n",
" if (root == None) :\n",
" return\n",
" # Increase distance between levels\n",
" space += COUNT[0]\n",
" # Process right leaf/branch/child first\n",
" print2DUtil_flat(root.rightAlphabet, space)\n",
" print()\n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" print(root.letter)\n",
" # Process left child\n",
" print2DUtil_flat(root.leftAlphabet, space)\n",
"\n",
" # Wrapper over print2DUtil()\n",
"def print2D(root) :\n",
" #Pass initial space count as 0\n",
" print(\"here is a tree that's laying on the ground: \")\n",
" print2DUtil_flat(root, 0)\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5f27d6d6-3019-4714-98d0-9650f1e087bb",
"metadata": {},
"outputs": [],
"source": [
"# utility to read the first letter of the input word \n",
"# press enter key, otherwise notebook will be pending\n",
"def grepFirstLetter():\n",
" word = input()\n",
" firstLetter = word[0]\n",
" return firstLetter\n",
" #print(\"the letter starts with : {}, and will be inserted under the {} leaf\".format(firstLetter, firstLetter))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "11081ff6-0295-4329-885c-6e6ddfddfcbf",
"metadata": {},
"outputs": [],
"source": [
"def insertLeaf(root,firstLetter):\n",
" #create new leaf \n",
" letterLeaf(firstLetter)\n",
" # python pointer implementation\n",
" # a root pointer \n",
" x = root\n",
" # pointer y maintains the trailing\n",
" # pointer of x\n",
" y = None\n",
" # traversal \n",
" # while x != none means the pointer can keep traversing\n",
" while(x != None):\n",
" y = x #trailing pointer points to x \n",
" if (firstLetter < x.letter):\n",
" x = x.leftAlphabet\n",
" else:\n",
" x = x.rightAlphabet\n",
" # insert leaf at root when tree is empty \n",
" if (y == None):\n",
" y = letterLeaf \n",
" # do string comparison, insert at left side of the alphabetTree \n",
" elif (firstLetter < x.letter):\n",
" x.leftAlphabet = letterLeaf\n",
" # insert at right side of the alphabetTree\n",
" else:\n",
" x.rightAlphabet = letterLeaf\n",
" return y\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "22301756-70e0-4ff7-b9bb-4f59c458058b",
"metadata": {},
"outputs": [],
"source": [
"# print binary tree in 2D copied from sample program\n",
"COUNT = [10]\n",
"def print2DUtil(root, space) :\n",
"\n",
" # Base case\n",
" if (root == None) :\n",
" return\n",
"\n",
" # Increase distance between levels\n",
" space += COUNT[0]\n",
"\n",
" # Process right child first\n",
" print2DUtil(root.rightAlphabet, space)\n",
"\n",
" # Print current node after space\n",
" # count\n",
" print()\n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" print(root.letter)\n",
"\n",
" # Process left child\n",
" print2DUtil(root.leftAlphabet, space)\n",
"\n",
"# Wrapper over print2DUtil()\n",
"def print2D(root) :\n",
" \n",
" # space=[0]\n",
" # Pass initial space count as 0\n",
" print2DUtil(root, 0)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "883373d0-cccc-4497-b9ff-af45670cb1ce",
"metadata": {},
"outputs": [],
"source": [
"# A utility function to insert a new\n",
"# Node with given key in BST\n",
"def insert(root, letter):\n",
"\n",
" # Create a new Node containing\n",
" # the new element\n",
" newleaf = letterLeaf(letter)\n",
"\n",
" # Pointer to start traversing from root\n",
" # and traverses downward path to search\n",
" # where the new node to be inserted\n",
" x = root\n",
"\n",
" # Pointer y maintains the trailing\n",
" # pointer of x\n",
" y = None\n",
"\n",
" while (x != None):\n",
" y = x\n",
" if (letter < x.letter):\n",
" x = x.leftAlphabet\n",
" else:\n",
" x = x.rightAlphabet\n",
" \n",
" # If the root is None i.e the tree is\n",
" # empty. The new node is the root node\n",
" if (y == None):\n",
" y = newleaf\n",
"\n",
" # If the new key is less then the leaf node key\n",
" # Assign the new node to be its left child\n",
" elif (letter < y.letter):\n",
" y.leftAlphabet = newleaf\n",
"\n",
" # else assign the new node its\n",
" # right child\n",
" else:\n",
" y.rightAlphabet = newleaf\n",
"\n",
" # Returns the pointer where the\n",
" # new node is inserted\n",
" return y\n",
"\n",
"# A utility function to do inorder\n",
"# traversal of BST"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "0f0bed93-2858-471b-b827-35f66da519b8",
"metadata": {},
"outputs": [],
"source": [
"def Inorder(root) :\n",
"\n",
" if (root == None) :\n",
" return\n",
" else:\n",
" Inorder(root.leftAlphabet)\n",
" print( root.letter, end = \" \" )\n",
" Inorder(root.rightAlphabet)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "e1884b95-8b53-49d6-b56c-a7226f14937e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'w', 'x', 'y', 'z']\n",
"\n",
" z\n",
"\n",
" y\n",
"\n",
" x\n",
"\n",
" w\n",
"\n",
"v\n",
"\n",
" u\n",
"\n",
" t\n",
"\n",
" s\n",
"\n",
" r\n",
"\n",
" q\n",
"\n",
" p\n",
"\n",
" o\n",
"\n",
" n\n",
"\n",
" m\n",
"\n",
" l\n",
"\n",
" k\n",
"\n",
" j\n",
"\n",
" i\n",
"\n",
" h\n",
"\n",
" g\n",
"\n",
" f\n",
"\n",
" e\n",
"\n",
" d\n",
"\n",
" c\n",
"\n",
" b\n",
"\n",
" a\n"
]
}
],
"source": [
"#Driver Code\n",
"import random\n",
"#if __name__ == '__main__':\n",
"\n",
"alphabet = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\",\"k\",\"l\",\"m\",\"n\",\"o\",\"p\",\"q\",\"r\",\"s\",\"t\",\"u\",\"v\",\"w\",\"x\",\"y\",\"z\"]\n",
"root = None\n",
"# pick a random letter in the alphabet\n",
"random_letter = random.choice(alphabet)\n",
"#print(random_letter)\n",
"#insert it into the tree, insert the first one \n",
"root = insert(root, random_letter)\n",
"# remove that letter from list\n",
"alphabet.remove(random_letter)\n",
"print(alphabet)\n",
"len_list = (len(alphabet))\n",
"#print(len_list)\n",
"while len_list > 0:\n",
" random_letter = random.choice(alphabet)\n",
" insert(root,random_letter)\n",
" alphabet.remove(random_letter)\n",
" #print(\"inserting and removing letter {} \".format(random_letter))\n",
" len_list -= 1\n",
"# keep inserting until the list is empty \n",
"# print tree \n",
"print2D(root)\n",
"# can try multiple times for different tree configurations"
]
},
{
"cell_type": "code",
"execution_count": 329,
"id": "d222d70f-2771-45be-9ac1-7ac579a242cb",
"metadata": {},
"outputs": [],
"source": [
"# print a vertical standing tree \n",
"# https://www.geeksforgeeks.org/print-level-order-traversal-line-line/\n",
"# https://www.geeksforgeeks.org/level-order-tree-traversal/"
]
},
{
"cell_type": "code",
"execution_count": 323,
"id": "39d68b3e-064e-4ed6-b10d-c7250a7034e3",
"metadata": {},
"outputs": [],
"source": [
"# a morse code tree\n",
"# https://www.101computing.net/morse-code-using-a-binary-tree/"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f7205015-dd4b-48bf-94c4-be0f96d8988a",
"metadata": {},
"outputs": [],
"source": [
"#firstLetter = grepFirstLetter()\n",
"#print(firstLetter)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,340 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "9da34557-037a-436f-bbaa-d332057cbe18",
"metadata": {},
"source": [
"# a letter tree, with fruits hanging, each starts with a different letter"
]
},
{
"cell_type": "code",
"execution_count": 129,
"id": "01acaa97-796a-4e34-9ee3-a46e71493d9d",
"metadata": {},
"outputs": [],
"source": [
"fruit_list = [\"apricot\",\"blood orange\",\"currant\",\"durian\",\"egg fruit\",\"fig\",\"guava\",\n",
" \"hawthorne\",\"jujube\",\"kiwi\",\"lychee\",\"mandarin\",\"nectarine\",\"olive\",\"persimmon\",\"quandong\",\"rambutan\",\"star fruit\",\n",
" \"tangor\",\"ugli fruit\",\"vanilla\",\"water chestnut\",\"ximenia\",\"yuzu\",\"zhe\"]\n",
"# additionally: longan yumberry sugarcane "
]
},
{
"cell_type": "code",
"execution_count": 130,
"id": "08ab8673-9b5c-4bd0-9fac-72796e831b94",
"metadata": {},
"outputs": [],
"source": [
"# build the fruit motley tree with extra utilities than the letter tree"
]
},
{
"cell_type": "code",
"execution_count": 131,
"id": "9c7187e4-0c49-4908-a169-775e6e475f94",
"metadata": {},
"outputs": [],
"source": [
"class letterLeaf:\n",
" def __init__(self,letter,wordFruit):\n",
" self.leftAlphabet = None\n",
" self.rightAlphabet = None\n",
" self.letter = letter\n",
" # try using a list structure to contain the words in this node? \n",
" self.wordFruit = wordFruit"
]
},
{
"cell_type": "code",
"execution_count": 132,
"id": "11dbf280-6c61-4020-bfe7-e85a723697db",
"metadata": {},
"outputs": [],
"source": [
"# printing tree utility \n",
"# this segment is modified from Shubham Singh(SHUBHAMSINGH10)'s contribution \n",
"\n",
"# spacer\n",
"COUNT = [10]\n",
"\n",
"# print a flat lying tree\n",
"# speculation this is a recursion that prints the right leaf until there is nothing left\n",
"def print2DUtil_flat(root, space) :\n",
" # Base case\n",
" if (root == None) :\n",
" return\n",
" # Increase distance between levels\n",
" space += COUNT[0]\n",
" # Process right leaf/branch/child first\n",
" print2DUtil_flat(root.rightAlphabet, space)\n",
" print()\n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" print(root.letter)\n",
" \n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" #print(root.letter) \n",
" print(root.wordFruit)\n",
" # Process left child\n",
" print2DUtil_flat(root.leftAlphabet, space)\n",
"\n",
" # Wrapper over print2DUtil()\n",
"def print2D(root) :\n",
" #Pass initial space count as 0\n",
" print(\"here is a tree that's laying on the ground: \")\n",
" print2DUtil_flat(root, 0)\n"
]
},
{
"cell_type": "code",
"execution_count": 133,
"id": "d0bcd376-491e-48e9-8bd9-e10d91346d7f",
"metadata": {},
"outputs": [],
"source": [
"#the input was for an interactive version like text input used by wang, save for later \n",
"def grepFirstLetter(word):\n",
" #word = input()\n",
" firstLetter = word[0]\n",
" return firstLetter\n",
" #print(\"the letter starts with : {}, and will be inserted under the {} leaf\".format(firstLetter, firstLetter))"
]
},
{
"cell_type": "code",
"execution_count": 134,
"id": "7a12a00f-f7b0-4234-a06c-54c6f3d1daf1",
"metadata": {},
"outputs": [],
"source": [
"# it will be parsed from the fruit basket\n",
"# pick a fruit\n",
"# hang onto tree\n",
"# parse the string letter by using the grepFirstLetter\n",
"def insertLeaf(root,wordFruit):\n",
" #create new leaf \n",
" letter = grepFirstLetter(wordFruit)\n",
" #print(\"first letter of {} is : {} \".format(wordFruit, letter))\n",
" #creating a new node containing firstLetter and wordFruit\n",
" newleaf = letterLeaf(letter,wordFruit)\n",
" #print(\"test print attributes {} {}\".format(newleaf.letter, newleaf.wordFruit))\n",
" # python pointer implementation\n",
" # a root pointer \n",
" x = root\n",
" # pointer y maintains the trailing\n",
" # pointer of x\n",
" # Pointer to start traversing from root\n",
" # and traverses downward path to search\n",
" # where the new node to be inserted\n",
" x = root\n",
"\n",
" # Pointer y maintains the trailing\n",
" # pointer of x\n",
" y = None\n",
"\n",
" while (x != None):\n",
" y = x\n",
" if (letter < x.letter):\n",
" x = x.leftAlphabet\n",
" else:\n",
" x = x.rightAlphabet\n",
" \n",
" # If the root is None i.e the tree is\n",
" # empty. The new node is the root node\n",
" if (y == None):\n",
" y = newleaf\n",
"\n",
" # If the new key is less then the leaf node key\n",
" # Assign the new node to be its left child\n",
" elif (letter < y.letter):\n",
" y.leftAlphabet = newleaf\n",
"\n",
" # else assign the new node its\n",
" # right child\n",
" else:\n",
" y.rightAlphabet = newleaf\n",
"\n",
" # Returns the pointer where the\n",
" # new node is inserted\n",
" return y\n",
"\n",
"\n",
"# A utility function to do inorder\n",
"# traversal of BST"
]
},
{
"cell_type": "code",
"execution_count": 135,
"id": "dc2230e9-0831-4e3c-93b8-c96d20fd0525",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"here is a tree that's laying on the ground: \n",
"\n",
" z\n",
" zhe\n",
"\n",
" y\n",
" yuzu\n",
"\n",
" x\n",
" ximenia\n",
"\n",
"w\n",
"water chestnut\n",
"\n",
" v\n",
" vanilla\n",
"\n",
" u\n",
" ugli fruit\n",
"\n",
" t\n",
" tangor\n",
"\n",
" s\n",
" star fruit\n",
"\n",
" r\n",
" rambutan\n",
"\n",
" q\n",
" quandong\n",
"\n",
" p\n",
" persimmon\n",
"\n",
" o\n",
" olive\n",
"\n",
" n\n",
" nectarine\n",
"\n",
" m\n",
" mandarin\n",
"\n",
" l\n",
" lychee\n",
"\n",
" k\n",
" kiwi\n",
"\n",
" j\n",
" jujube\n",
"\n",
" h\n",
" hawthorne\n",
"\n",
" g\n",
" guava\n",
"\n",
" f\n",
" fig\n",
"\n",
" e\n",
" egg fruit\n",
"\n",
" d\n",
" durian\n",
"\n",
" c\n",
" currant\n",
"\n",
" b\n",
" blood orange\n",
"\n",
" a\n",
" apricot\n"
]
}
],
"source": [
"# same deal, insert everything in the list until it's empty \n",
"import random\n",
"\n",
"root = None\n",
"# pick a random letter in the alphabet\n",
"random_fruit = random.choice(fruit_list)\n",
"#print(random_letter)\n",
"#insert it into the tree, insert the first one \n",
"root = insertLeaf(root, random_fruit)\n",
"# remove that letter from list\n",
"fruit_list.remove(random_fruit)\n",
"#print(fruit_list)\n",
"len_list = (len(fruit_list))\n",
"#print(len_list)\n",
"while len_list > 0:\n",
" random_fruit = random.choice(fruit_list)\n",
" insertLeaf(root,random_fruit)\n",
" fruit_list.remove(random_fruit)\n",
" #print(\"inserting and removing letter {} \".format(random_letter))\n",
" len_list -= 1\n",
"# keep inserting until the list is empty \n",
"# print tree \n",
"print2D(root)\n",
"# can try multiple times for different tree configurations\n"
]
},
{
"cell_type": "code",
"execution_count": 136,
"id": "6fc4208f-8088-476d-b20d-0f0ac0e85066",
"metadata": {},
"outputs": [],
"source": [
"# fruits in structured presetations:\n",
"# https://zhuanlan.zhihu.com/p/113457497\n",
"# https://www.wordmom.com/fruits/that-start-with-w"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7bd7553d-8ed4-436b-b4cf-99395a4f91b9",
"metadata": {},
"outputs": [],
"source": [
"# more fun stuff\n",
"# https://en.wikipedia.org/wiki/Flora_Sinensis\n"
]
},
{
"cell_type": "markdown",
"id": "5b11e6fc-0443-4373-8530-5f2b2f1b0aa7",
"metadata": {},
"source": [
"During a potluck dinner in Beijing Adel brought an dish made from pomegrante seeds. It was in December, the crowd was not used to the fruit salad dish. Adel was the only Iranian there. A talented cook as Adel was, the dish was barely touched. \n",
"Adel, I think you would agree with me that international potlucks are as bad as they can be. Let's hang the fruits high up - trees are good to store and access memories. For the pomegrantes seeds that I've missed that evening. "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,383 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "59b5e56e-137c-4c72-8832-3fb7e625fddc",
"metadata": {},
"source": [
"# a longan tree\n",
"# 龙眼树"
]
},
{
"cell_type": "markdown",
"id": "1d3d5765-21b5-4022-8fb6-995feadbd000",
"metadata": {},
"source": [
"## what is longan?\n",
"Dimocarpus longan, commonly known as the longan, is a tropical tree species that produces edible fruit. It is one of the better-known tropical members of the soapberry family Sapindaceae,to which the lychee and rambutan also belong. The fruit of the longan is similar to that of the lychee, but less aromatic in taste."
]
},
{
"cell_type": "markdown",
"id": "8bd7458b-bbb1-4977-9f78-a4f8f2e93985",
"metadata": {},
"source": [
"### a photo of a longan tree with fruits\n",
"from reddit post https://www.reddit.com/r/gardening/comments/8cfh6n/our_glorious_longan_tree/"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "39a00b5f-45ca-4356-ad0e-b2cef2593ef1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<img src=\"images/longan_tree.jpg\" width=\"400\" height=\"400\"/>"
],
"text/plain": [
"<IPython.core.display.Image object>"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import Image\n",
"url_tree = \"images/longan_tree.jpg\"\n",
"Image(url= url_tree, width=400, height=400)"
]
},
{
"cell_type": "markdown",
"id": "547e4b39-856f-4374-a23a-b95917817749",
"metadata": {},
"source": [
"## what is the soapberry family Sapindaceae?\n",
"The Sapindaceae are a family of flowering plants in the order Sapindales known as the soapberry family. \n"
]
},
{
"cell_type": "markdown",
"id": "9a0050aa-eabb-4407-971e-abd89f9ddb17",
"metadata": {},
"source": [
"### why is knowing the soapberry family important for the longan tree"
]
},
{
"cell_type": "markdown",
"id": "68ba1fba-d0f0-4e6f-952b-07ae19262df8",
"metadata": {},
"source": [
"As we know the longan tree is one tree species under the soapberry family, we can track the other tree species relevant to the longan tree. The lychee tree, the rambutan tree, and the longan tree are closely related to each other. "
]
},
{
"cell_type": "markdown",
"id": "0af3e49f-f417-4779-afc8-9932be9539f5",
"metadata": {},
"source": [
"This is written in early spring, and longan fruits are harvested during the summer. In villages in Southern China, harvesting longan fruits \"摘龙眼\"is a fun summer activity. "
]
},
{
"cell_type": "markdown",
"id": "7ba8cd22-532f-424c-8c57-96990a8903fd",
"metadata": {},
"source": [
"Longan also means \"dragon eye\". The fruit is round, resembling an eyeball of a dragon. There is also the \"phoenix eye\"(凤眼),referring to eyes that has a long-ish shape and tilts upwards. "
]
},
{
"cell_type": "markdown",
"id": "3f133efd-1adf-40f0-acb6-24fbff03bebb",
"metadata": {},
"source": [
"In a gender binary context, suppose there is a pair of twins that's a boy and a girl. In Chinese such pair of twins is refered to as \"dragon and phoenix twin\"(龙凤胎)。Suppose the girl has the \"phonenix eyes\"(凤眼), then would the boy eat loads of \"dragon eyes\"(龙眼)?!\n",
"在性别二元对立的语境下,有一对龙凤胎,女孩有一双凤眼,那男孩岂不是有一双龙眼?!"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "23f11815-0327-4027-8e4a-6004595e9525",
"metadata": {},
"outputs": [],
"source": [
"eyes_l = [\"⊙\",\"ಠ\",\"ಡ\",\"⚆\",\n",
" \"✪\",\"◙\",\"*\",\"°\",\n",
" \"☉\",\"⚈\",\"๏\",\"◔\",\n",
" \"◉\",\"ʘ\",\"Θ\",\"❍\",\n",
" \"●\",\"ᓂ\",\"ᓀ\",\"•͈\",\n",
" ]"
]
},
{
"cell_type": "markdown",
"id": "e9181f99-311b-4788-bba1-3781b62dc7f8",
"metadata": {},
"source": [
"## dragon eyes of various affects\n",
"呆萌的龙眼,迟疑的龙眼,左顾右盼的龙眼,闪烁其辞的龙眼。\n",
"被踩扁的龙眼,爆了浆的龙眼,剥开皮的龙眼,被掏空的龙眼。"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "f74f4027-9305-4862-adb9-3bd46bae37ad",
"metadata": {},
"outputs": [],
"source": [
"# build a tree from eyes_l\n",
"# can try a binary tree structure\n",
"# however, a longan tree cannot be arbitrarily defined as using\n",
"# the bst structure\n",
"# are there other tree branching structures to try? "
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "35a275f8-71d4-4354-b019-befc9650c042",
"metadata": {},
"outputs": [],
"source": [
"# starting from a yard of trees: longan, lychee and rombutan "
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "fe8cc549-0ffe-4d55-afb3-a49605fca2c1",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"soapberry forest\n",
"├── longan\n",
"├── lychee\n",
"└── rombutan\n"
]
}
],
"source": [
"from anytree import Node, RenderTree\n",
"# build tree\n",
"soapberryForest = Node(\"soapberry forest\")\n",
"longan = Node(\"longan\", parent=soapberryForest)\n",
"lychee = Node(\"lychee\", parent=soapberryForest)\n",
"rombutan = Node(\"rombutan\", parent=soapberryForest)\n",
"\n",
"# print tree\n",
"for pre, fill, node in RenderTree(soapberryForest):\n",
"\tprint(\"%s%s\" %(pre,node.name))"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "a651378f-02e3-4da4-8510-3754af471cc2",
"metadata": {},
"outputs": [],
"source": [
"# bst tree template \n",
"\"\"\"Python3 program to demonstrate insert\n",
"operation in binary search tree \"\"\"\n",
"\n",
"# A Binary Tree Node\n",
"# Utility function to create a\n",
"# new tree node\n",
"class newNode:\n",
"\n",
" # Constructor to create a newNode\n",
" def __init__(self, data):\n",
" self.key= data\n",
" self.left = None\n",
" self.right = self.parent = None\n",
"\n",
"# A utility function to insert a new\n",
"# Node with given key in BST\n",
"def insert(root, key):\n",
"\n",
" # Create a new Node containing\n",
" # the new element\n",
" newnode = newNode(key)\n",
"\n",
" # Pointer to start traversing from root\n",
" # and traverses downward path to search\n",
" # where the new node to be inserted\n",
" x = root\n",
"\n",
" # Pointer y maintains the trailing\n",
" # pointer of x\n",
" y = None\n",
"\n",
" while (x != None):\n",
" y = x\n",
" if (key < x.key):\n",
" x = x.left\n",
" else:\n",
" x = x.right\n",
" \n",
" # If the root is None i.e the tree is\n",
" # empty. The new node is the root node\n",
" if (y == None):\n",
" y = newnode\n",
"\n",
" # If the new key is less then the leaf node key\n",
" # Assign the new node to be its left child\n",
" elif (key < y.key):\n",
" y.left = newnode\n",
"\n",
" # else assign the new node its\n",
" # right child\n",
" else:\n",
" y.right = newnode\n",
"\n",
" # Returns the pointer where the\n",
" # new node is inserted\n",
" return y\n",
"\n",
"#Driver Code\n",
"if __name__ == '__main__':\n",
"\n",
" root = None\n",
" root = insert(root, \"longan tree\")\n",
" for eye in eyes_l:\n",
" insert(root,eye)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "ef3979c3-7da9-4bb3-a691-4a210da308cb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
" ❍\n",
"\n",
" ✪\n",
"\n",
" ⚈\n",
"\n",
" ⚆\n",
"\n",
" ☉\n",
"\n",
" ◙\n",
"\n",
" ◔\n",
"\n",
" ●\n",
"\n",
" ◉\n",
"\n",
" ⊙\n",
"\n",
" •͈\n",
"\n",
" ᓂ\n",
"\n",
" ᓀ\n",
"\n",
" ๏\n",
"\n",
" ಡ\n",
"\n",
" ಠ\n",
"\n",
" Θ\n",
"\n",
" ʘ\n",
"\n",
" °\n",
"\n",
"longan tree\n",
"\n",
" *\n"
]
}
],
"source": [
"COUNT = [10]\n",
"def print2DUtil(root, space) :\n",
"\n",
" # Base case\n",
" if (root == None) :\n",
" return\n",
"\n",
" # Increase distance between levels\n",
" space += COUNT[0]\n",
"\n",
" # Process right child first\n",
" print2DUtil(root.right, space)\n",
"\n",
" # Print current node after space\n",
" # count\n",
" print()\n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" print(root.key)\n",
"\n",
" # Process left child\n",
" print2DUtil(root.left, space)\n",
"\n",
"# Wrapper over print2DUtil()\n",
"def print2D(root) :\n",
" \n",
" # space=[0]\n",
" # Pass initial space count as 0\n",
" print2DUtil(root, 0)\n",
"\n",
"# Driver Code\n",
"if __name__ == '__main__':\n",
"\n",
" \n",
" print2D(root)"
]
},
{
"cell_type": "markdown",
"id": "d8d8b5fa-49cf-47e5-8c69-a0285b286030",
"metadata": {},
"source": [
"a pun, a poem, a puoem. "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,314 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "29e43a9b-4fe9-4fa4-83fc-8bc7cc733914",
"metadata": {},
"source": [
"# a morse code tree"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "85da8440-0286-4fc5-8009-a1dbbbeaf195",
"metadata": {},
"outputs": [],
"source": [
"# https://www.101computing.net/morse-code-using-a-binary-tree/"
]
},
{
"cell_type": "code",
"execution_count": 62,
"id": "18c38e4e-67f6-4814-a9ee-014af7b231dd",
"metadata": {},
"outputs": [],
"source": [
"# modified left and right pointers to dot and dash\n",
"class Node:\n",
" def __init__(self, value, dot=None, dash=None):\n",
" self.value = value\n",
" self.dot = dot\n",
" self.dash = dash"
]
},
{
"cell_type": "code",
"execution_count": 63,
"id": "93595ce3-cbd6-4b58-ad8d-b25d89a14b11",
"metadata": {},
"outputs": [],
"source": [
"def getMorseCode(node, character, code):\n",
" if node==None:\n",
" return False\n",
" elif node.value==character:\n",
" # return to end program\n",
" return True\n",
" # keep traversing when the pointer is not pointing to null\n",
" else: \n",
" if getMorseCode(node.dot,character,code)==True:\n",
" code.insert(0,\".\")\n",
" return True\n",
" elif getMorseCode(node.dash,character,code)==True:\n",
" code.insert(0,\"-\")\n",
" return True"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "1da7f6e4-114b-4087-a777-65a21525a51b",
"metadata": {},
"outputs": [],
"source": [
"# printing tree utility \n",
"# this segment is modified from Shubham Singh(SHUBHAMSINGH10)'s contribution \n",
"\n",
"# spacer\n",
"COUNT = [10]\n",
"\n",
"# print a flat lying tree\n",
"# speculation this is a recursion that prints the right leaf until there is nothing left\n",
"def print2DUtil_flat(root, space) :\n",
" # Base case\n",
" if (root == None) :\n",
" return\n",
" # Increase distance between levels\n",
" space += COUNT[0]\n",
" # Process right leaf/branch/child first\n",
" print2DUtil_flat(root.dash, space)\n",
" print()\n",
" for i in range(COUNT[0], space):\n",
" print(end = \" \")\n",
" print(root.value)\n",
" \n",
" #for i in range(COUNT[0], space):\n",
" # print(end = \" \")\n",
" #print(root.letter) \n",
" #print(root.value)\n",
" # Process left child\n",
" print2DUtil_flat(root.dot, space)\n",
"\n",
" # Wrapper over print2DUtil()\n",
"def print2D(root) :\n",
" #Pass initial space count as 0\n",
" print(\"here is a tree that's laying on the ground: \")\n",
" print2DUtil_flat(root, 0)\n"
]
},
{
"cell_type": "code",
"execution_count": 77,
"id": "c0e844a1-3d41-40e5-afde-9ff16de294d9",
"metadata": {},
"outputs": [],
"source": [
"#Let's initialise our binary tree:\n",
"tree = Node(\"START\") #The root node of our binary tree\n",
"\n",
"# 1st Level\n",
"tree.dot = Node(\"E\")\n",
"tree.dash = Node(\"T\")\n",
"\n",
"# 2nd Level\n",
"tree.dot.dot = Node(\"I\")\n",
"tree.dot.dash = Node(\"A\")\n",
"tree.dash.dot = Node(\"N\")\n",
"tree.dash.dash = Node(\"M\")\n",
"\n",
"# 3rd Level\n",
"tree.dot.dot.dot = Node(\"S\")\n",
"tree.dot.dot.dash = Node(\"U\")\n",
"tree.dot.dash.dot = Node(\"R\")\n",
"tree.dot.dash.dash = Node(\"W\")\n",
"\n",
"tree.dash.dot.dot = Node(\"D\")\n",
"tree.dash.dot.dash = Node(\"K\")\n",
"tree.dash.dash.dot = Node(\"G\")\n",
"tree.dash.dash.dash = Node(\"O\")\n",
"\n",
"# 4th Level\n",
"tree.dot.dot.dot.dot = Node(\"H\")\n",
"tree.dot.dot.dot.dash = Node(\"V\")\n",
"tree.dot.dot.dash.dot = Node(\"F\")\n",
"tree.dot.dot.dash.dash = Node(\"\")\n",
"tree.dot.dash.dot.dot = Node(\"L\")\n",
"tree.dot.dash.dot.dash = Node(\"\")\n",
"tree.dot.dash.dash.dot = Node(\"P\")\n",
"tree.dot.dash.dash.dash = Node(\"J\")\n",
"\n",
"tree.dash.dot.dot.dot = Node(\"B\")\n",
"tree.dash.dot.dot.dash = Node(\"X\")\n",
"tree.dash.dot.dash.dot = Node(\"C\")\n",
"tree.dash.dot.dash.dash = Node(\"Y\")\n",
"tree.dash.dash.dot.dot = Node(\"Z\")\n",
"tree.dash.dash.dot.right = Node(\"Q\")\n",
"tree.dash.dash.dash.dot = Node(\"\")\n",
"tree.dash.dash.dash.dash = Node(\"\")\n",
"\n",
"# how to insert letters without entering one by one? use what structure?\n"
]
},
{
"cell_type": "code",
"execution_count": 78,
"id": "be1252af-f941-47c1-a717-dd04f53e0c68",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"here is a tree that's laying on the ground: \n",
"\n",
" \n",
"\n",
" O\n",
"\n",
" \n",
"\n",
" M\n",
"\n",
" G\n",
"\n",
" Z\n",
"\n",
" T\n",
"\n",
" Y\n",
"\n",
" K\n",
"\n",
" C\n",
"\n",
" N\n",
"\n",
" X\n",
"\n",
" D\n",
"\n",
" B\n",
"\n",
"START\n",
"\n",
" J\n",
"\n",
" W\n",
"\n",
" P\n",
"\n",
" A\n",
"\n",
" \n",
"\n",
" R\n",
"\n",
" L\n",
"\n",
" E\n",
"\n",
" \n",
"\n",
" U\n",
"\n",
" F\n",
"\n",
" I\n",
"\n",
" V\n",
"\n",
" S\n",
"\n",
" H\n"
]
}
],
"source": [
"# print morse code tree configuration\n",
"print2D(tree)"
]
},
{
"cell_type": "code",
"execution_count": 79,
"id": "c9e6e242-c742-416e-b2cb-550d4e7a8ff2",
"metadata": {},
"outputs": [
{
"name": "stdin",
"output_type": "stream",
"text": [
"Enter a message to convert into Morse Code: (e.g. SOS) hwllo\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
".... .-- .-.. .-.. --- \n"
]
}
],
"source": [
"#Message Input\n",
"message = input(\"Enter a message to convert into Morse Code: (e.g. SOS)\").upper()\n",
"morseCode = \"\"\n",
"\n",
"#Convert the message, one character at a time!\n",
"for character in message:\n",
" dotsdashes = []\n",
" getMorseCode(tree,character,dotsdashes)\n",
" code = \"\".join(dotsdashes)\n",
" morseCode = morseCode + code + \" \"\n",
"print(morseCode)"
]
},
{
"cell_type": "markdown",
"id": "93252875-0f4f-40f8-af62-b027f916eb60",
"metadata": {},
"source": [
"# todo \n",
"modify the tree print out to show the dots and dashes \n",
"take a user input in morse code, and use the binary tree to decode the message one character at a time\n",
"translate the dot dash signals into other forms of pulsations: LED light, sound to be sent out via radio signal, ?FSK (written on the code memo)\n",
"would be nice to emphasize the traversal aspect, can it be displayed / heard - traversing to the dot! traversing to the dash! make it procedural -> maybe console can be helpful "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ddeba74b-f6bc-4e06-ab2b-3b176a485bc9",
"metadata": {},
"outputs": [],
"source": [
"# reference project\n",
"# https://microbit-micropython.readthedocs.io/en/latest/tutorials/radio.html\n",
"# https://new.pythonforengineers.com/blog/audio-and-digital-signal-processingdsp-in-python/"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

@ -0,0 +1,91 @@
import time
with open('corpus/words') as f:
lines = f.readlines()
print(lines)
class letterLeaf:
def __init__(self,letter,wordFruit):
self.leftAlphabet = None
self.rightAlphabet = None
self.letter = letter
self.wordFruit = wordFruit
COUNT = [10]
def print2DUtil_flat(root, space,growth_rate):
if (root == None) :
return
space += COUNT[0]
print2DUtil_flat(root.rightAlphabet, space,growth_rate)
print()
for i in range(COUNT[0], space):
print(end = " ")
print(root.letter)
for i in range(COUNT[0], space):
print(end = " ")
print(root.wordFruit)
time.sleep(growth_rate)
print2DUtil_flat(root.leftAlphabet, space,growth_rate)
def print2D(root, growth_rate):
print("here is a tree that's laying on the ground: ")
print2DUtil_flat(root, 0, growth_rate)
def grepFirstLetter(word):
firstLetter = word[0]
return firstLetter
def insertLeaf(root,wordFruit):
letter = grepFirstLetter(wordFruit)
newleaf = letterLeaf(letter,wordFruit)
x = root
y = None
while (x != None):
y = x
if (letter < x.letter):
x = x.leftAlphabet
else:
x = x.rightAlphabet
if (y == None):
y = newleaf
elif (letter < y.letter):
y.leftAlphabet = newleaf
else:
y.rightAlphabet = newleaf
return y
import random
root = None
random_fruit = random.choice(fruit_list)
root = insertLeaf(root, random_fruit)
fruit_list.remove(random_fruit)
len_list = (len(fruit_list))
while len_list > 0:
random_fruit = random.choice(fruit_list)
insertLeaf(root,random_fruit)
fruit_list.remove(random_fruit)
len_list -= 1
def ask_input():
growth_rate = int(input("Enter growth rate value for tree in seconds: "))
return growth_rate
growth_rate = ask_input()
print2D(root, growth_rate)

@ -1 +1,7 @@
remove the empty projects that i will no longer work on find a meaningful corpus to feed the program with text data, just like expanding on a list, but must be in a meaningful way.
remove empty projects
more housekeeping work:
clean up programs

@ -0,0 +1,104 @@
import sys
import time
import random
# hard coded in
sys.setrecursionlimit(1000000000)
print(sys.getrecursionlimit())
corpus = []
with open('corpus/words') as f:
corpus = f.readlines()
corpus = [word.strip() for word in corpus]
fruit_list = corpus
#print(fruit_list)
class letterLeaf:
def __init__(self,letter,wordFruit):
self.leftAlphabet = None
self.rightAlphabet = None
self.letter = letter
self.wordFruit = wordFruit
COUNT = [10]
def print2DUtil_flat(root, space,growth_rate):
if (root == None) :
return
space += COUNT[0]
print2DUtil_flat(root.rightAlphabet, space,growth_rate)
print()
for i in range(COUNT[0], space):
print(end = " ")
print(root.letter)
for i in range(COUNT[0], space):
print(end = " ")
print(root.wordFruit)
time.sleep(growth_rate)
print2DUtil_flat(root.leftAlphabet, space,growth_rate)
def print2D(root, growth_rate):
print("here is a tree that's laying on the ground: ")
print2DUtil_flat(root, 0, growth_rate)
def grepFirstLetter(word):
firstLetter = word[0]
return firstLetter
def insertLeaf(root,wordFruit):
letter = grepFirstLetter(wordFruit)
newleaf = letterLeaf(letter,wordFruit)
x = root
y = None
while (x != None):
y = x
if (letter < x.letter):
x = x.leftAlphabet
else:
x = x.rightAlphabet
if (y == None):
y = newleaf
elif (letter < y.letter):
y.leftAlphabet = newleaf
else:
y.rightAlphabet = newleaf
return y
import random
root = None
random_fruit = random.choice(fruit_list)
root = insertLeaf(root, random_fruit)
fruit_list.remove(random_fruit)
len_list = (len(fruit_list))
while len_list > 0:
random_fruit = random.choice(fruit_list)
insertLeaf(root,random_fruit)
fruit_list.remove(random_fruit)
len_list -= 1
def ask_input():
growth_rate = int(input("Enter growth rate value for tree in seconds: "))
return growth_rate
growth_rate = ask_input()
print2D(root, growth_rate)
Loading…
Cancel
Save