自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(15)
  • 收藏
  • 关注

原创 字符串-删除多余的元素

#去掉空格 strip() 方法能用于删除开始或结尾的字符s = ’ hello world \n’print(s.strip())print(s)t = ‘-----hello=====’print(t.strip("-"))#处理中间的空格s = ’ hello world \n’print(s.replace(" “,”"))...

2019-11-07 15:08:54 257

原创 字符串-贪婪匹配与最短匹配

?强制最短匹配 *+是贪婪匹配 ?强制最短匹配text1 = 'Computer says "no."'text2 = 'Computer says "no." Phone says "yes."'str_pat=re.compile(r'"(.*)"')str_pat1=re.compile(r'"(.*?)"')str_pat1=re.compile(r'"(.*?)"')...

2019-11-07 14:26:17 265

原创 字符串-忽略大小写搜索和替换

import retext = 'UPPER PYTHON, lower python, Mixed Python'print(re.findall(r"python",text,flags=re.IGNORECASE)) #返回列表print(re.sub(r"python","java",text,flags=re.IGNORECASE))

2019-11-07 10:26:06 209

原创 字符串-搜索和替换

“”"1、字符串的搜索和替换,简单的使用str.replace()方法2、复杂模式,使用re.sub()函数“”"text = "yeah, but no, but yeah, but no, but yeah"print(text.replace("yeah","yes")) #text.replace()不返回值text = 'Today is 11/27/2012. Py...

2019-11-07 10:07:20 109

原创 python数据结果-list数据过滤

import mathmylist = [1, 4, -5, 10, -7, 2, 3, -1]#列表推导式 缺陷:数据量大的时候占用内存比较大filter_list=[n for n in mylist if n>0]print(filter_list)#方法2,使用生成器表达式pos=(n for n in mylist if n>0)for x in po...

2019-11-06 13:53:52 1216

原创 python数据结构-从一个字典构建一个子集字典

prices = { 'ACME': 45.23, 'AAPL': 612.78, 'IBM': 205.55, 'HPQ': 37.20, 'FB': 10.75}P1={key:value for key,value in prices.items() if value>200}print(P1)tech_names = {'AAPL',...

2019-11-06 10:35:05 240

原创 python数据结构-统计序列中单词出现的次数

出一个序列中出现次数最多的元素方法一:from collections import Counterwords = [‘look’, ‘into’, ‘my’, ‘eyes’, ‘look’, ‘into’, ‘my’, ‘eyes’,‘the’, ‘eyes’, ‘the’, ‘eyes’, ‘the’, ‘eyes’, ‘not’, ‘around’, ‘the’,‘eyes’, ...

2019-11-06 10:23:53 136

原创 python数据结构-字典排序

根据某个或某几个字典字段来排序这个列表from operator import itemgetterrows = [ {'fname': 'Brian', 'lname': 'Jones', 'uid': 1003}, {'fname': 'David', 'lname': 'Beazley', 'uid': 1002}, {'fname': 'John', 'lna...

2019-11-06 10:02:08 105

原创 python数据结构--字典分组记录

1、通过某个字段将记录分组使用场景:字典或者实例的序列,然后你想根据某个特定的字段比如 date 来分组迭代访问from operator import itemgetterfrom itertools import groupbyrows = [ {'address': '5412 N CLARK', 'date': '07/01/2012'}, {'address...

2019-11-06 09:45:44 230

原创 DAY6 python练习

求出列表的中位数,并输出L = [98, 78, 15, 30, 87, 36, 22, 3, 74, 61, 38, 68, 52, 10, 16, 15, 5, 39, 22, 97]def get_midian(L): L.sort(reverse=True) num = len(L) if num % 2 == 0: a, b = L[(num ...

2019-09-09 13:53:15 106

原创 DAY5 python练习

“”"请用正则表达式,找出下面字符串中所有c开头的单词,结果是一个列表,列表里面每一个元素是一个单词’ “”"import res =“”"And now, the end is near  And so I face the final curtain  My friend, I’ll make it clearI’ll state my case, of which I’m c...

2019-09-05 14:53:27 83

原创 DAY4 python练习

初级题1.判断一个数是否是回文数。此题需要使用input()输入一段字符串,然后判断输入的字符串是否是回文数输入:123321输出:True输入:121输出:True输入:24lwsr输出:Falses=input("请输入:")if s[::]==s[::-1]: print(True)else: print(False)2.字符串旋转。对于一个字符串,我...

2019-08-28 15:58:05 167

原创 DAY3 Python作业

1.给定一个列表L1 = [53, 40, 10, 37, 91, 97, 87, 45, 15, 12, 29, 21, 73, 77, 91, 55, 46, 64, 37, 29]计算器平均数,并输出from functools import reduceList1 = [53, 40, 10, 37, 91, 97, 87, 45, 15, 12, 29, 21, 73, 77, ...

2019-08-23 16:23:37 120

原创 DAY1 Python作业

def list_test():list1 = [1, 2, 3, 4, 5]list2 = [6, 7, 8, 9]list3 = []for i in range(len(list1)): list3.append(list1[i]) list3.append(list2[i])return list3#print(list_test())import re...

2019-08-22 16:12:49 85

原创 DAY2,Python作业

初级题:给定两个长度相等的列表,要求对应相加再存入第三个列表中L1 = [1,2,3,4]L2 = [2,3,4,5]得出L3 = [3,5,7,9]然后输出L3第一种方法:L3 = list(map(lambda x, y: x+y, L1, L2))第二种方法:L4 = []for i in range(len(L1)):L4.append(int(L1[i]+L2[i]...

2019-08-22 16:07:08 132

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除