社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  sahasrara62  »  全部回复
回复总数  3
5 年前
回复了 sahasrara62 创建的主题 » Python,使用字典和集合来跟踪单词的所有出现
n = int(input())
dic  = {}

for _ in range(n):
  w = input()
  if w in dic.keys():
    dic[w]+=1
  else:
    dic.update({w:1})

print(len(dic.keys()))
print(*dic.values())
6 年前
回复了 sahasrara62 创建的主题 » 从另一个包Python导入类

在里面 module_1.py 导入为 from . import module_2 src.py 将模块1导入为 from pkg_1 import module_1

这是解决办法,你不必担心学生的分数。

list1=['student1',10,20,40,'student2',20,20,40,'student3',20,30,40,'student4',20,10,30]

student_name =[]
student_name_index =[]

for i in range(len(list1)):        
    if type(list1[i]) == int:
        pass
    else:
        student_name.append(list1[i])
        student_name_index.append(i)

student_name_index.append(len(list1)-1)

total_marks=[]

for i in range(1,len(student_name_index)):
    total_marks.append(sum(list1[student_name_index[i-1]+1:student_name_index[i]]))

final_result =[]

for name, mark in zip(student_name,total_marks):
    final_result.append(name)
    final_result.append(mark)

print(final_result)

# output ['student1', 70, 'student2', 80, 'student3', 90, 'student4', 30]