Fix: week4 ex4

This commit is contained in:
2026-03-23 23:02:45 +08:00
parent e1d2d137c5
commit df970263d1
2 changed files with 47 additions and 3 deletions

View File

@@ -1,3 +1,26 @@
# ICSP Works
ICSP课程相关的工程文件夹托管于私人git服务器。
ICSP课程相关的工程文件夹托管于私人git服务器。**请勿发送到其他校外线上平台。请勿攻击此网站。**
仓库地址: https://git.et3.my/eterill/ICSP1-Works
个人博客https://eterill.xyz/
## 命名说明
`/week(\d+)`:对应某一周课程的内容
`/week(\d+)/run_all.py`:依次运行当周全部的程序
`/week(\d+)/ex(\d+)`:当周对应练习的代码
## 其他说明
### 这个`.gitignore`是什么文件?
这是一个用来避免python运行的缓存上传到服务器的一个控制文件您可以询问ai了解详情。
### 为什么这些代码这么离谱?
这是我初中开始自学的Python是我了解到的第一门非图形化编程语言
总之用了一些高阶技巧和语法糖不必在意可以发给ai问问相关的技法
## 代码好像有问题?
欢迎来告诉我!这些代码基本都是仓促编写的,没有经过严格测试,也经不起生产环境级的测试,如果你发现了问题可以发送邮件到[eterill@hotmail.com](mailto:eterill@hotmail.com)或者[e@eterill.xyz](mailto:e@eterill.xyz)
如果你想问点其他的,欢迎来班级群找我!

View File

@@ -2,15 +2,26 @@ def main():
from random import randint
print('==Exercise 4==')
LIST_A = [1,2.0,'c',{"id":4}]
LIST_B = [randint(1,100) for i in range(10)]
LIST_B = [randint(1,20) for i in range(10)]
LIST_C = [*[chr(i+65) for i in range(10)],27,28.0]
print('Lists Initial Values:')
"""
updated on Mar 23th 23:00
课上写的有点问题,重写了
print(f'{i["idtf"]}: {i["value"]}' for i in [
{"idtf":"List A","value":LIST_A},
{"idtf":"List B","value":LIST_B},
{"idtf":"List C","value":LIST_C},
])
"""
print(*[f'{i["idtf"]}: {i["value"]}' for i in [
{"idtf":"List A","value":LIST_A},
{"idtf":"List B","value":LIST_B},
{"idtf":"List C","value":LIST_C},
]],sep='\n')
print('a range of items: ',LIST_C[:-3])
print('reverse print of list: ',LIST_C[::-1])
@@ -23,8 +34,18 @@ def main():
LIST_B.sort()
print('sorting List B:',LIST_B)
"""
updated on Mar 23th 22:54
课上写的有点问题,重写了
print('number of similar items in the list B: ',sum([1 if LIST_B[i] in LIST_B[i+1:] else 0 for i in range(len(LIST_B))]))
"""
TEMP_DICT_SIMCOUNTER = {}
for i in LIST_B:
if i in TEMP_DICT_SIMCOUNTER: TEMP_DICT_SIMCOUNTER[i]+=1
else: TEMP_DICT_SIMCOUNTER[i]=1
print('number of similar items in the list B: ',*[f'{i}:{TEMP_DICT_SIMCOUNTER[i]} times ' if TEMP_DICT_SIMCOUNTER[i]>1 else "" for i in TEMP_DICT_SIMCOUNTER.keys()],sep='')
print('==End Of Ex4==')
return 0