面试总结
import reemail_list = ["xiaoWang@163.cn", "xiaoWang@163.comheihei", "xiaowang@qq.com"]for email in email_list: # ret = re.match("[\w]{4,20}@163\.com$", email) # ret = re.match(r'^[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net]{1,3}$', email) # ret = re.match(r'^[\w]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net]{1,3}$', email) ret = re.match(r'^[\w]{0,19}@(?:qq|163|126)\.[com,cn,net]{1,3}$', email) # ret = re.match("[\w]{4,20}@[163,qq]+\.com$", email) if ret: print("%s 是符合规定的邮件地址,匹配后的结果是:%s" % (email, ret.group())) else: print("%s 不符合要求" % email)
import restr = "15827325743"print(re.match(r"^1[3-9]\d{9}$", str).group())
for i in range(1,10): for j in range(1,i+1): print("%s*%s=%s"%(i,j,i*j),end=" ") print()
print ("\n".join("\t".join(["%s*%s=%s" %(x,y,x*y) for y in range(1, x+1)]) for x in range(1, 10)))
list = [1, 2, 3, 4, 5, 6, 5, 4, 3, ]def fun(list): for i in range(len(list) - 1): for j in range(len(list) - i - 1): if list[j] > list[j + 1]: list[j], list[j + 1] = list[j + 1], list[j]fun(list)print(list)
print([a+b for a in ["a","b","c"] for b in["x", "y", "z"]])
i,j = 1,1while i < 1000: print(i) i,j = j,i+j
nums = [2, 7, 11, 15]class Solution(object): def twoSum(self, nums, target): if len(nums) <= 1: return False buff_dict = {} for i in range(len(nums)): if nums[i] in buff_dict: return [buff_dict[nums[i]], i] else: buff_dict[target - nums[i]] = ia1 = Solution()print(a1.twoSum(nums,13))
#! /usr/bin/env python# *-* coding: utf-8 *-*a = [1, 2, 3, 4, 5, 5, 5, 3, 4]b = list({i: a.index(i) for i in a}.keys())print("取最大值", max(b))print("利用字典去重后得到的结果", b)b1_dict = {i: a.count(i) for i in a}print("拿到的字典", b1_dict)# 将b1这个字典按值的大小进行排序sorted_dict = sorted(b1_dict.items(), key=lambda x: x[1], reverse=True)print("排序的字典", sorted_dict[0:2])# 排序(出现频率前三的)from collections import Counterc = Counter(a).most_common(3)print(c)"""取最大值 5利用字典去重后得到的结果 [1, 2, 3, 4, 5]拿到的字典 {1: 1, 2: 1, 3: 2, 4: 2, 5: 3}排序的字典 [(5, 3), (3, 2)][(5, 3), (3, 2), (4, 2)]"""