![](https://img-blog.csdnimg.cn/20201014180756724.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
文章平均质量分 62
chendian920311
这个作者很懒,什么都没留下…
展开
-
python 字典/集合操作
字典的基本操作1、如何访问字典中的值?adict[key] 形式返回键key对应的值value,如果key不在字典中会引发一个KeyError。2、如何检查key是否在字典中?a、has_key()方法 形如:adict.haskey(‘name') 有–>True,无–>Falseb、in 、not in 形如:'name' in adict 有–>原创 2015-07-09 13:57:32 · 570 阅读 · 0 评论 -
python zip map
1.zip平行遍历操作1 >>> name=('jack','beginman','sony','pcky') 2 >>> age=(2001,2003,2005,2000) 3 >>> for a,n in zip(name,age): 4print a,n 5 6输出: 7 jack 2001 8 beginman 2003 9 sony 200510 pcky 2000原创 2015-07-09 14:00:49 · 579 阅读 · 0 评论 -
python 列表推导 求100内的素数
列表推导式(list comprehension)是利用其他列表创建新列表(类似于数学术语中的集合推导式)的一种方法。它的工作方式类似于for循环,也很简单:In [39]: [x*x for x in range(10)]Out[39]: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]比如一个字典如下:a={1:2,2:3,3:4},要求链接字典的键值,并且原创 2015-07-09 14:01:49 · 12179 阅读 · 0 评论 -
378. Kth Smallest Element in a Sorted Matrix
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth smallest element in the sorted order, not原创 2016-09-14 16:48:26 · 362 阅读 · 0 评论 -
python 切片,字符串逆序神器
字符串、列表、元组在python中都符合“序列”这一特征,只要符合这一特征的变量我们都可以用切片(slice)去存取它们的任意部分。我们可以把序列想像成一个队列,我可能需要前面三位、后面三位、或从第三位后的四位、或隔一个取一个等,我们用切片操作符来实现上述要求。切片操作符在python中的原型是[start:stop:step] 即:[开始索引:结束索引:步长值]步长>0 切原创 2015-07-09 13:59:10 · 7900 阅读 · 2 评论