- 博客(12)
- 收藏
- 关注
原创 django.db.utils.OperationalError: (2002, “Can‘t connect to server on ‘172.0.0.1‘ (10060)“) 报错解决方案
修改settings中数据库配置的HOST,由127.0.0.1改为localhost修改后
2022-12-07 11:51:31 914
原创 python练习:反转列表里的元素
lst=[1,5,2,3,4]k=[]for l in reversed(lst): k.append(l)print(k)
2021-08-31 18:56:17 145
原创 python练习:两个列表,找出B列表包含A列表的元素
a=[1,2,3,7]b=[1,2,3,4,5]c=[]for i in a: if i in b: c.append(i)print(c)
2021-08-31 16:08:47 637
原创 python练习:输出去重后列表
l=[1,1,3,3]l2=[]for i in l: if i not in l2: l2.append(i)print(l2)
2021-08-24 12:48:33 386
原创 python练习:字母异位词分组
str_dict = {}strs=['sbc','scb','13','31','a']for s in strs: t = "".join(sorted(s)) if t in str_dict: str_dict[t].append(s) else: str_dict[t] = [s]print(str_dict.values())
2021-08-22 18:41:58 86
原创 python正则:贪婪匹配与非贪婪匹配
import rel='a1d22d'#贪婪匹配在匹配元素间用 .*tanlan=re.match('a.*d',l)#非贪婪匹配在匹配元素间用 .*?untanlan=re.match('a.*?d',l)print("贪婪匹配结果是%s"%tanlan.group()+"\n非贪婪匹配结果是%s"%untanlan.group())...
2021-08-22 11:25:01 51
原创 python练习:将[1,2,3,4]变为“1234”
l=[1,2,3,4]lst=[str(i) for i in l] #将原列表中的数字转为字符串new_lst=''.join(lst)print(new_lst)
2021-08-22 10:41:41 1381 2
原创 python练习:求一个列表中出现最多次数的元素
lst=[1,2,3,3,'w','w','w','w','g']dict={}for i in lst: num=lst.count(i) dict[i]=nummax_num=max(dict.values())most_emt=list(dict.keys())[list(dict.values()).index(max_num)]print('出现最多次数的元素是:%s'%most_emt)
2021-08-20 23:09:21 1367
原创 python练习:冒泡排序
lst=[9,6,5,4,3,2,1,7,8]for i in range(len(lst)): for j in range(len(lst)-i-1): if lst[j]>lst[j+1]: lst[j+1],lst[j]=lst[j],lst[j+1]print(lst)
2021-08-20 22:04:02 279
原创 python练习:对10个数进行排序。
lst = []new_lst =[]for j in range(10): i = int(input("请输入一个整数:")) lst.append(i)print("原始顺序:")print(lst)for m in range(len(lst)-1): for n in range(m+1,len(lst)): if lst[m]>lst[n]: k=lst[m] lst[m]=lst[n].
2021-07-14 22:41:13 6327
原创 python练习:输入某年某月某日,判断这一天是这一年的第几天?
year=int(input('请输入年:'))month=int(input('请输入月:'))day=int(input('请输入日:'))run_month=[1,3,5,7,8,10,12]#闰月有这几个num=0if (year % 400 == 0) or ((year % 4 == 0) and (year % 100 != 0)): feb = 29 #闰年2月是29天else: feb = 28for mth in range(1,month): ...
2021-06-30 23:48:30 4894 3
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人