python - 改进嵌套循环搜索
问题描述
所以这来自我对嵌套循环所做的一个黑客等级问题: https ://www.hackerrank.com/challenges/nested-list/problem
我的解决方案通过了所有测试用例,但我想知道如何提高效率。即如何减少运行时间和内存分配。
if __name__ == '__main__':
test = []
second = []
for _ in range(int(input())):
name = input()
score = float(input())
test.append([name,score])
second.append(score)
test = sorted(test, key=lambda x:x[1], reverse =True)
second = sorted(list(set(second)))
second = second[1]
out = [student[0] for student in test if student[1]==second]
out = sorted(out)
[print(x) for x in out]
解决方案
推荐阅读
- django-cms - 通过 django-cms API 创建的页面 404
- r - 区域统计 R(栅格/多边形)
- python - 合并 Panda Dataframes - 保留原始订单并覆盖列
- python - 如何使用 boto3 将 html 文件和 helloworld.py 文件复制到 ec2 实例
- visual-studio - Xamarin.Forms android.support.v4.app.TaskStackBuilder 未找到
- javascript - 从同一设备进行第二次注册尝试时未执行 Firestore 写入操作
- python - 将工作方向设置为 Python 中的脚本方向(pyinstaller)
- python - 将曲线拟合到数据,获得分析形式,并检查曲线何时越过阈值
- function - 调用 BAPI_USER_CHANGE 后如何从返回表中获取所有消息?
- javascript - 使用 Jquery 隐藏 DisplayFor 元素