result = sorted([item for item in map(lambda x:x, ['bob','about','Zoo','Credit'])], key=str.casefold)
print(result)
print(result)
2025-08-15
def cal_prod(list_):
def f(x,y):
return x*y
def mul():
return reduce(f,list_)
return mul
res = cal_prod([1,3,5,8])
print(res())
def f(x,y):
return x*y
def mul():
return reduce(f,list_)
return mul
res = cal_prod([1,3,5,8])
print(res())
2025-08-15
result = sorted([item for item in ['bob', 'about', 'Zoo', 'Credit']], key = str.casefold)
print(result)
print(result)
2025-08-15
import math
def is_n(d):
for i in range(d+1):
if i == math.sqrt(d):
return d
for item in filter(is_n, [x for x in range(1,101)]):
print(item)
def is_n(d):
for i in range(d+1):
if i == math.sqrt(d):
return d
for item in filter(is_n, [x for x in range(1,101)]):
print(item)
2025-08-15
def f(x):
return x[0].upper() + x[1:].lower()
for item in map(f,['alice', 'BOB', 'CanDY']):
print(item)
return x[0].upper() + x[1:].lower()
for item in map(f,['alice', 'BOB', 'CanDY']):
print(item)
2025-08-15
import math
def add(x,y,f):
return f(x) + f(y)
result = add(1,4,math.sqrt)
print(result)
def add(x,y,f):
return f(x) + f(y)
result = add(1,4,math.sqrt)
print(result)
2025-08-15
import requests
resp = requests.get('http://idcbgp.cn')
content = str(resp.content,encoding='utf-8')
content_list = content.split('\n')
for line in content_list:
if 'www' in line:
print(line.strip())
resp = requests.get('http://idcbgp.cn')
content = str(resp.content,encoding='utf-8')
content_list = content.split('\n')
for line in content_list:
if 'www' in line:
print(line.strip())
2025-08-15
import requests
response = requests.get('http://127.0.0.1:8000/')
print(response.status_code)
print(response.headers)
response = requests.get('http://127.0.0.1:8000/')
print(response.status_code)
print(response.headers)
2025-08-15
from urllib import request
response = request.urlopen('http://127.0.0.1:8000/')
print(response.status)
for k,v in response.getheaders():
print('{}: {}'.format(k,v))
response = request.urlopen('http://127.0.0.1:8000/')
print(response.status)
for k,v in response.getheaders():
print('{}: {}'.format(k,v))
2025-08-15
with open('test.txt','a+') as f:
f.seek(0)
content = f.readlines()
f.write('\n')
f.seek(2)
for line in content:
f.write(line)
f.seek(0)
content = f.readlines()
f.write('\n')
f.seek(2)
for line in content:
f.write(line)
2025-08-15
with open('test.txt', 'r') as i_f:
lines = i_f.readlines()
r_lines = []
for line in lines:
s_line = line.rstrip('\n')
r_line = s_line[::-1]
if line.endswith('\n'):
r_line += '\n'
r_lines.append(r_line)
with open('test1.txt', 'w') as o_file:
o_file.writelines(r_lines)
lines = i_f.readlines()
r_lines = []
for line in lines:
s_line = line.rstrip('\n')
r_line = s_line[::-1]
if line.endswith('\n'):
r_line += '\n'
r_lines.append(r_line)
with open('test1.txt', 'w') as o_file:
o_file.writelines(r_lines)
2025-08-15
f = open('D:\桌面\python_practice123\TX\practice.txt', 'r')
print(f.read())
f.close()
print(f.read())
f.close()
2025-08-14
win+R->cmd
python -m venv myenv #create virtul environment
myenv/Scripts/activate #Activate it
pip install requests
python -m venv myenv #create virtul environment
myenv/Scripts/activate #Activate it
pip install requests
2025-08-14