housekeeping stuffed, parse large dictionary
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 |
@ -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,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,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)
|
||||
|