2018-8-27未命名文件
Posted cerofang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018-8-27未命名文件相关的知识,希望对你有一定的参考价值。
面试总结
- 匹配邮箱
import re
email_list = ["[email protected]", "[email protected]", "[email protected]"]
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 re
str = "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 ("
".join(" ".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"]])
- 字典推导式
daibuchong
- 斐波那契数列
i,j = 1,1
while 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]] = i
a1 = 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 Counter
c = 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)]
"""
以上是关于2018-8-27未命名文件的主要内容,如果未能解决你的问题,请参考以下文章