Unverified Commit dc112ff7 authored by Maxim Belkin's avatar Maxim Belkin Committed by GitHub

08-defensive.md: move the last exercise to 'Extras' (#714)

The last exercise in `08-defensive.md` has a few issues:

a. it uses unclear language ("Fix" may refer to many things)
b. it uses functions not (currently) introduced in the lesson -- builtin `max` and `min`

Both issues can be fixed. Until then, we're moving this exercise to "Extras"
parent fa3f16ef
......@@ -538,27 +538,4 @@ This violates another important rule of programming:
> {: .solution}
{: .challenge}
> ## Fixing and Testing
>
> Fix `range_overlap`. Re-run `test_range_overlap` after each change you make.
>
> > ## Solution
> > ~~~
> > def range_overlap(ranges):
> > '''Return common overlap among a set of [left, right] ranges.'''
> > if not ranges:
> > # ranges is None or an empty list
> > return None
> > max_left, min_right = ranges[0]
> > for (left, right) in ranges[1:]:
> > max_left = max(max_left, left)
> > min_right = min(min_right, right)
> > if max_left >= min_right: # no overlap
> > return None
> > return (max_left, min_right)
> > ~~~
> > {: .language-python}
> {: .solution}
{: .challenge}
{% include links.md %}
......@@ -49,3 +49,29 @@ or not (yet) added to the main lesson.
> > list and then unpacked into `left` and `right`.
> {: .solution}
{: .challenge}
> ## Fixing and Testing
> From: "Defensive Programming"
>
> Fix `range_overlap`. Re-run `test_range_overlap` after each change you make.
>
> > ## Solution
> > ~~~
> > def range_overlap(ranges):
> > '''Return common overlap among a set of [left, right] ranges.'''
> > if not ranges:
> > # ranges is None or an empty list
> > return None
> > max_left, min_right = ranges[0]
> > for (left, right) in ranges[1:]:
> > max_left = max(max_left, left)
> > min_right = min(min_right, right)
> > if max_left >= min_right: # no overlap
> > return None
> > return (max_left, min_right)
> > ~~~
> > {: .language-python}
> {: .solution}
{: .challenge}
{% include links.md %}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment