jackfrued / jackfrued/Python-100-Days

Day 7 Exercise 4 Bug

Open
#561 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
187k
Forks
55.8k
PR merge metrics
No merged PRs in 30d

Description

设计一个函数返回传入的列表中最大和第二大的元素的值。

参考的代码可能存在bug,例如[4, 3, 5, 6, 7]这样从第三个元素开始就是顺序的情况,其实现有代码是无法找出最大的两个的,因为每次循环只会替换第一个,这样的话,可能用选择性排序(只做两次)会不会好一些?

for i in range(2):
for j in range(i, len(list_copy)):
if list_copy[j] > list_copy[i]:
list_copy[i], list_copy[j] = list_copy[j], list_copy[i]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at Day 7 Exercise 4 and compare its reference implementation with the supplied [4, 3, 5, 6, 7] case. Run the relevant notebook cell and verify that the function returns the largest and second-largest values; done means the reported pair is correct for that case and ordinary list inputs.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
content
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.