摘要:1 turtle绘制奥运五环图 import turtle as p def drawCircle(x,y,c='red'): p.pu()# 抬起画笔 p.goto(x,y) # 绘制圆的起始位置 p.pd()# 放下画笔 p.color(c)# 绘制c色圆环 p.circle(30,360) #
阅读全文
摘要:1#测试函数执行时间的装饰器示例 import time def timing_func(fn): def wrapper(): start=time.time() fn() #执行传入的fn参数 stop=time.time() return (stop-start) return wrapper
阅读全文
摘要:1 寻找第n次出现位置 def search_n(s, c, n): size = 0 for i, x in enumerate(s): if x == c: size += 1 if size == n: return i return -1 print(search_n("fdasadfadf
阅读全文
摘要:4G 内存处理 10G 大小的文件,单机怎么做? 下面的讨论基于的假定:可以单独处理一行数据,行间数据相关性为零。 方法一: 仅使用 Python 内置模板,逐行读取到内存。 使用 yield,好处是解耦读取操作和处理操作: def python_read(filename): with open(
阅读全文
摘要:1.主线程 import threading t = threading.current_thread() print(t) # <_MainThread(MainThread, started 139908235814720)> print(t.getName()) # MainThread pr
阅读全文
摘要:1.年的日历图 import calendar from datetime import date mydate = date.today() year_calendar_str = calendar.calendar(2019) print(f"{mydate.year}年的日历图:{year_c
阅读全文
摘要:1.获取后缀名 import os file_ext = os.path.splittext('./data/py/test.py') front,ext = file_ext print(front,ext) #'./data/py/test' #'.py' 2.创建文件夹 def mkdir(p
阅读全文
摘要:stringbook旋转后得到bookstring,写一段代码验证str1是否为str2旋转得到。 思路 转化为判断:str1是否为str2+str2的子串(因为该思路比较巧妙,故记录下来) def is_rotation(s1: str, s2: str) -> bool: if s1 is No
阅读全文
摘要:[str("java"[i%3*4:]+"python"[i%5*6:] or i) for i in range(1,15)]
阅读全文
摘要:今天看见一个烧脑的代码,一时没看懂结果,刨个坑,看懂填 def product(*args, repeat=1): pools = [tuple(pool) for pool in args] * repeat result = [[]] for pool in pools: result = [x
阅读全文
摘要:1.""" # Write a program to compute:## f(n)=f(n-1)+100 when n>0# and f(0)=1## with a given n input by console (n>0).## Example:# If the following n is
阅读全文
摘要:1. """ Write a program that accepts a sentence and calculate the number of upper case letters and lower case letters. Suppose the following input is s
阅读全文
摘要:1. """ Write a program which can compute the factorial of a given numbers. The results should be printed in a comma-separated sequence on a single lin
阅读全文