- 博客(3)
- 资源 (2)
- 收藏
- 关注
原创 Python中bisect模块用法,及实现方式
#bisect用法:import bisectbisect.bisect_left(t,x) #在T列表中查找x,若存在,返回x左侧位置bisect.bisect_right(t,x)bisect.insort_left(t,x) #在T列表中查找X,若存在,插入x左侧;bisect.insort_right(t,x)下面是其实现的方法,实际是二分法:def binary
2015-09-28 22:24:17
2992
原创 二分法查找的Python实现
代码如下:#!/usr/bin/env python# coding=utf-8def BinarySearch(t,x): t.sort() #对列表进行排序,列表是有序的,是二分法的前提 low = 0; high = len(t)-1; while low < high: mid = (low+high)/2; if
2015-09-27 22:05:35
3779
原创 生日悖论的Python实现
题目:如果你的班级中有23个学生,那么其中有两个人生日相同的概率为多大?#!/usr/bin/env python# coding=utf-8import random;def has_duplicates(t): s = t[:]; #make a copy of original list s.sort(); for i in range(len(
2015-09-26 22:31:52
5315
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人 TA的粉丝