阅读OReilly.Web.Scraping.with.Python.2015.6笔记---找出网页中所有的href 1.查找以<a>开头的所有文本,然后判断href是否在<a>里面,如果<a>里面有href,就像<a href=" " >,然后提取href的值. from urllib.request import urlopen from bs4 import BeautifulSoup html = urlopen("ht…
http://bbs.chinaunix.net/thread-1680208-1-1.html 如何找出 python list 中有重复的项 http://www.cnblogs.com/feisky/archive/2012/12/06/2805251.html 比较容易记忆的是用内置的setl1 = ['b','c','d','b','c','a','a']l2 = list(set(l1))print l2 还有一种据说速度更快的,没测试过两者的速度差别l1 = ['b','c','d…
需求: 快速的获取一个列表中最大/最小的n个元素. 方法: 最简便的方法是使用heapq模组的两个方法nlargest()和nsmallest(),例如: In [1]: import heapqIn [2]: nums = [1, 0, -23, 45, 34, -11, 0, 2, 99, 103, -78]In [3]: print(heapq.nlargest(3, nums))[103, 99, 45]In [4]: print(heapq.nsmallest(3, nums))[-7…
生物信息:找出基因,生物学家使用字母A.C.T和G构成的字符串建模一个基因组.一个基因是基因组的子串,它从三元组ATG后开始在三元组TAG.TAA或TGA之前结束.此外,基因字符串的长度是3的倍数,而且基因不包含三元组ATG.TAG.TAA和TGA.编写程序提示用户输入一个基因组,然后显示基因组里的所有基因.如果在输入序列中没有找到基因,那么程序显示“no gene is found” s=input('Please input the Gene String:\r\n') endsplit=[…
代码: import geocoder g = geocoder.ip('me') print(g.latlng) # 经纬度 print(g.city) # 所在城市 输出: C:\Users\horn1\Desktop\python\49-geo>python geo.py [38.9122, 121.602] Dalian 参考资料:https://blog.csdn.net/hailangnet/article/details/53287585 很可惜其它的API都报: Status c…
1.生成随机字典 # 从abcdefg 中随机取出 3-6个,作为key, 1-4 的随机数作为 value s1 = {x : randint(1, 4) for x in sample('abcdefg', randint(3, 6))} 方法1 用集合方法 s1 = {'c': 3, 'f': 3, 'g': 3, 'd': 4, 'b': 2} s2 = {'b': 3, 'f': 2, 'c': 2} s3 = {'f': 3, 'b': 1, 'c': 4, 'd': 3, 'g':…
SHOW DATABASES; 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢.…
#如'abbcc','abbdd' 找到abba='abbcc'b='abbdd'from difflib import *s=SequenceMatcher(None,a,b)m=s.find_longest_match(0,len(a),0,len(b))print a[m.a:m.a+m.size]…
# 方法一 利用max min 函数. 注意这里max min 分别都是功能函数 def main_m(*args): i = max(args) j = min(args) print("最大值是%s" % i) print("最小值是%s" % j) list1 = [23,56,8,99]main_m(*list1) # 方法二 给max min 变量赋初值(这里max 和min 都是变量) 然后遍历容器将所需的最大和最小值分别赋给两个变量 def main_…