Skip to content

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

Description

@natanlao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions