Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secondsmallest() in 11_selection.md is broken #15

Open
natanlao opened this issue Feb 25, 2021 · 0 comments
Open

secondsmallest() in 11_selection.md is broken #15

natanlao opened this issue Feb 25, 2021 · 0 comments

Comments

@natanlao
Copy link

For example:

>>> def secondsmallest(L):
...     a, b = None, None
...     for item in L:
...         if a is None or item <= b:
...             a, b = item, a
...         elif b is None or item <= a:
...             b = item
...     return b
>>> secondsmallest([4, 5, 1, 2, 3])
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 4, in secondsmallest
TypeError: '<=' not supported between instances of 'int' and 'NoneType'

secondsmallest() does not account for when the second element in L is larger than the first element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant