python记录 trees
来源:互联网 发布:阿里云宽带是什么 编辑:程序博客网 时间:2024/06/06 18:26
log()函数:
log()方法返回x的自然对数,对于x>0。
以下是log()方法的语法:
import
math
math.log( x )
- x -- 这是一个数值表达式。
返回值
此方法返回x的自然对数,对于x>0。
另外,可以通过log(x[, base])来设置底数,如 log(x, 10) 表示以10为底的对数。
for example in dataset: --------for循环,在数据dataset(可以是列表、元组、集合、字典等)中 逐个取值存入 变量 example中,然后运行循环体。
python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和sysmmetric difference(对称差集)等数学运算.
sets 支持 x in set, len(set),和 for x in set。作为一个无序的集合,sets不记录元素位置或者插入点。因此,sets不支持 indexing, slicing, 或其它类序列(sequence-like)的操作。
>>> x =
set
(
'spam'
)
>>> y =
set
([
'h'
,
'a'
,
'm'
])
>>> x, y
(
set
([
'a'
,
'p'
,
's'
,
'm'
]),
set
([
'a'
,
'h'
,
'm'
]))
>>> x & y
# 交集
set
([
'a'
,
'm'
])
>>> x | y
# 并集
set
([
'a'
,
'p'
,
's'
,
'h'
,
'm'
])
>>> x - y
# 差集
set
([
'p'
,
's'
])
去除海量列表里重复元素,用hash来解决也行,只不过感觉在性能上不是很高,用set解决还是很不错的,示例如下:
>>> a = [11,22,33,44,11,22]
>>> b =
set
(a)
>>> b
set
([33, 11, 44, 22])
>>> c = [i
for
i
in
b]
>>> c
[33, 11, 44, 22]
count() 方法用于统计某个元素在列表中出现的次数。
语法
count()方法语法:
参数
- obj -- 列表中统计的对象。
返回值
返回元素在列表中出现的次数。
实例
以下实例展示了 count()函数的使用方法:
以上实例输出结果如下:
del()
用于list列表操作,删除一个或者连续几个元素。
index()函数
一般用处是在序列中检索参数并返回第一次出现的索引,没找到就会报错,比如:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
但参数可能会出现很多次,要如何做呢?
index()函数的完整语法是这样的:
str.index(str, beg=0, end=len(string))
str – 指定检索的字符串
beg – 开始索引,默认为0。
end – 结束索引,默认为字符串的长度。
所以我们可以重新设置开始索引来继续寻找,如:
- 1
- 2
因为第一个’l’的出现位置是1,所以我们将开始索引加1继续寻找,果然,在索引为2的位置又找到了’l’。
- python记录 trees
- trees
- 【LeetCode with Python】 Unique Binary Search Trees
- 【LeetCode】【Python题解】Unique Binary Search Trees
- Unique Binary Search Trees II Leetcode Python
- 【Leetcode】【python】Unique Binary Search Trees
- 【Leetcode】【python】Unique Binary Search Trees II
- python--leetcode617. Merge Two Binary Trees
- python 记录
- python记录
- Python记录
- python 记录
- python 记录
- python记录
- Python 记录
- python 记录
- 个人记录-LeetCode 95. Unique Binary Search Trees II
- 个人记录-LeetCode 96. Unique Binary Search Trees
- 每天学一点python---模块,导入模块
- 【Scikit-Learn 中文文档】寻求帮助
- MFC应用程序框架(文档类)
- python 正则表达式基础
- 【Scikit-Learn 中文文档】处理文本数据
- python记录 trees
- 二进制部署kubernetes1.7.4
- 插值与逼近(一):Lagrange插值
- BitmapFactory.decodeResource(getResources(),R.drawable.a)获取不到值
- 关于软件工程课程的感想
- Servlet容器的一个简单实现
- 在屏幕上用“*”显示0~360度的余弦函数cos(x)曲线
- 爬取斗破苍穹整本小说
- servet