python 由递归的dict构建树的画图代码
createPlot(mytree)方法实现。
其中myTree是一个字典,调用retrieveTree(0)可以获得一个字典的样式。
Last login: Thu Feb 23 19:07:53 on ttys000
B000000060143:~ zhanghao44$ ls
4 Desktop IdeaProjects Music PycharmProjects
4a Documents Library Pictures
CLionProjects Downloads Movies Public
B000000060143:~ zhanghao44$ cd Desktop/
B000000060143:Desktop zhanghao44$ ls
help
machinelearninginaction
ps-dsp
终端
备份
屏幕快照 2017-02-22 下午7.36.56.png
屏幕快照 2017-02-22 下午7.41.27.png
屏幕快照 2017-02-22 下午7.45.55.png
张浩出勤统计.xlsx
B000000060143:Desktop zhanghao44$ cd machinelearninginaction/
B000000060143:machinelearninginaction zhanghao44$ ls
Ch02 Ch05 Ch08 Ch11 Ch14
Ch03 Ch06 Ch09 Ch12 Ch15
Ch04 Ch07 Ch10 Ch13 README.rst
B000000060143:machinelearninginaction zhanghao44$ cd Ch03
B000000060143:Ch03 zhanghao44$ ls
classifierStorage.txt treePlotter.py trees.py
lenses.txt treePlotter.pyc trees.pyc
B000000060143:Ch03 zhanghao44$ vi trees.py
B000000060143:Ch03 zhanghao44$ vi treePlotter.py B000000060143:Ch03 zhanghao44$ vi treePlotter.py plotTree.totalD = float(getTreeDepth(inTree))
plotTree.xOff = -0.5/plotTree.totalW; plotTree.yOff = 1.0;
plotTree(inTree, (0.5,1.0), '')
plt.show() def createPlot1():
fig = plt.figure(1, facecolor='white')
fig.clf()
createPlot.ax1 = plt.subplot(111, frameon=False) #ticks for demo puropses
plotNode('a decision node', (0.5, 0.1), (0.1, 0.5), decisionNode)
plotNode('a leaf node', (0.8, 0.1), (0.3, 0.8), leafNode)
plt.show() def retrieveTree(i):
listOfTrees =[{'no surfacing': {0: 'no', 1: {'flippers': {0: 'no', 1: 'yes'}}}},
{'no surfacing': {0: 'no', 1: {'flippers': {0: {'head': {0: 'no', 1: 'yes'}}, 1: 'no'}}}}
]
return listOfTrees[i] #createPlot(thisTree)
python 由递归的dict构建树的画图代码的更多相关文章
- Python的递归
递归 是指函数/过程/子程序在运行过程序中直接或间接调用自身而产生的重入现象.在计算机编程里,递归指的是一个过程:函数不断引用自身,直到引用的对象已知.使用递归解决问题,思路清晰,代码少.但是在主流高 ...
- Python基础——字典(dict)
由键-值对构建的集合. 创建 dic1={} type(dic1) dic2=dict() type(dic2) 初始化 dic2={'hello':123,'world':456,'python': ...
- Python中list,tuple,dict,set的区别和用法
Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python的四个内置数据类型功不可没,他们即是list, tuple, dict, set.这里对他们进行一个简明的总结. List ...
- 为 Python Server Pages 和 Oracle 构建快速 Web 开发环境。
为 Python Server Pages 和 Oracle 构建快速 Web 开发环境. - 在水一方 - 博客频道 - CSDN.NET 为 Python Server Pages 和 Oracl ...
- python基础之字典dict和集合set
作者:tongqingliu 转载请注明出处:http://www.cnblogs.com/liutongqing/p/7043642.html python基础之字典dict和集合set 字典dic ...
- Python中list,tuple,dict,set的区别和用法(转)
原文地址:http://www.cnblogs.com/soaringEveryday/p/5044007.html Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python的四个 ...
- 关于python最大递归深度 - 998
今天LeetCode的时候暴力求解233 问题: 给定一个整数 n,计算所有小于等于 n 的非负数中数字1出现的个数. 例如: 给定 n = 13, 返回 6,因为数字1出现在下数中出现:1,10,1 ...
- python入门14 字典dict
字典dict是无序的key:value格式的数据序列 #coding:utf-8 #/usr/bin/python """ 2018-11-11 dinghanhua 字 ...
- Python的递归深度
RuntimeError: maximum recursion depth exceeded while calling a Python object 大意是调用 Python 对象时超出最大深度限 ...
随机推荐
- DOM(四):h5扩展方法
getElementByClassName()方法getElementByClassName()方法接收一个参数,即一个包含一或多个类名的字符串,返回带有指定类的所有元素的NodeList //取得所 ...
- 【转载】刘昕明:送给和我一样曾经浮躁过的PHP程序员
刘昕明:送给和我一样曾经浮躁过的PHP程序员 来源:刘昕明博客 作者:刘昕明 2012年偶决定开始写博客了,不为别的,就希望可以通过博客记录我的成长历程同时也希望可以帮助一些刚毕业,刚 ...
- 旧文备份:安装cygwin及在console下输入和显示中文
1.下载Cygwin.exe文件,双击安装,首先在"Choose A Download Source"的时候选择"Download Without Installing& ...
- cookie和session的介绍
1.cookie和session cookie不属于http协议范围,由于http协议无法保持状态,但实际情况,我们却又需要“保持状态”,因此产生cookie. cookie的工作原理是:由服务器产生 ...
- 如何导入CSV数据 (python3.6.6区别于python2 环境)
1.python2环境下 2.python3.6.6环境下 如果用python2环境下的代码,在python3.6.6环境下编译会出现以下问题: 错误(1): SyntaxError:Missing ...
- 深度CNN
[具体参考可以看这里(https://cloud.tencent.com/developer/article/1369425)
- python文件操作练习之文件备份
文件备份 ## 文件备份 # 打开文件 def backup(file1, file2): with open(file1, 'rb') as f1,\ open(file2, 'wb') as f2 ...
- rootfls(根操作系统)
rootfs根文件系统,linux下的任何目录都是rootfs的一个路径 Files 文件 Directory 目录 FHS(文件层级标准)规定了linux发行标准,也就是一些固定的文件存储 文件 ...
- PAT (Basic Level) Practice 1023 组个最小数
个人练习 给定数字 0-9 各若干个.你可以以任意顺序排列这些数字,但必须全部使用.目标是使得最后得到的数尽可能小(注意 0 不能做首位).例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的 ...
- POJ:2429-GCD & LCM Inverse(素数判断神题)(Millar-Rabin素性判断和Pollard-rho因子分解)
原题链接:http://poj.org/problem?id=2429 GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K To ...