[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
前言
初学Python,有几次作业时遇到过提取字符串中的小写字母或大写字母的问题,网上查阅了下,没有明了的代码来实现(太简单了,都没人写的),自己今天实现了,并且稍稍就题目升华了下用途,所以就写出来,方便以后查阅
实现
写了个函数来实现从字符串中提取小写字母,代码如下
def extract(string1): length = len(string1) list1 = [] for i in range(length):
if string1[i].islower(): list1.append(string1[i]) return list1
运行实例如下
升华
Python是跟着小甲鱼学的,做的题目也是小甲鱼出的,其中有这么一道题,要求在长字符串中找到密码,密码埋藏符合以下规律:
a) 每位密码为单个小写字母
b) 每位密码左右两边均有且只有三个大写字母
代码实现如下
def pj_psd(string1): length = len(string1) list1 = [] psd = []
#先找出文件中所有小写字母的索引 for i in range(length): if string1[i].islower():
list1.append(i) length1 = len(list1) for j in range(length1): if
((string1[(list1[j]-3):list1[j]]).isupper()) and
((string1[(list1[j]+1):(list1[j]+4)]).isupper()): psd.append(string1[list1[j]])
str2 = '' for each in psd: str2 += each return str2
运行实例如下
总结
学了Python发现可以干点实事,不像之前学的编程语言,有些空中楼阁的感觉,继续加油