Skip to content

Commit 306482f

Browse files
Yrahcaz7BethanyG
andauthored
Apply suggestions from code review
Co-authored-by: BethanyG <BethanyG@users.noreply.github.com>
1 parent 14eef29 commit 306482f

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

exercises/practice/reverse-string/.approaches/additional-approaches/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def reverse(text):
2323
# Calculate the index start.
2424
location = index + seq_len + 1
2525

26-
# Prepend the byte segment to the output bytearray
26+
# Prepend the byte segment to the output bytearray.
2727
output[-location:-index or None] = given[index:index + seq_len]
2828

2929
# Increment the index count / slide the 'window'.

exercises/practice/reverse-string/.approaches/built-in-reversed/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def reverse(text):
2020
This version uses `reversed()` to reverse a `range()` object rather than feed a `start`/`stop`/`step` to `range()` itself.
2121
It then uses the reverse `range` to iterate over the input string and concatenate each code point to a new `output` string.
2222
This has over-complicated `reversed()`, as it can be called directly on the input string with almost no overhead.
23-
This has also incurs the performance hit of repeated concatenation to the `output` string.
23+
This has also incured the performance hit of repeated concatenation to the `output` string.
2424

2525
While this approach _looks_ as if it would be similar to the first, it is actually `O(n**2)` in time complexity due to string concatenation.
2626
It was also the slowest in benchmarks.

exercises/practice/reverse-string/.approaches/list-and-join/content.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def reverse(text):
9191
return output.decode("utf-8")
9292
```
9393

94-
This variation is operationally the same as variations #2 and #3 above, except that it encodes the string to a `utf-8` [`bytearray`](https://docs.python.org/3/library/stdtypes.html#bytearray).
94+
This variation is operationally the same as variations #2 and #3 above, except that it encodes the string to a `utf-8` [`bytearray`][bytearray-docs].
9595
It then iterates over the `bytearray` to perform the swaps.
9696
Finally, the `bytearray` is decoded into a `utf-8` string to return the reversed word.
9797
This incurs overhead when encoding/decoding to and from the `bytearray`.
@@ -138,3 +138,4 @@ The [`timeit`][timeit] module docs have more details, and [note.nkmk.me][note_nk
138138
[note_nkmk_me]: https://note.nkmk.me/en/python-timeit-measure/
139139
[timeit]: https://docs.python.org/3/library/timeit.html#python-interface
140140
[approach-additional-approaches]: https://exercism.org/tracks/python/exercises/reverse-string/approaches/additional-approaches
141+
[bytearray-docs]: https://docs.python.org/3/library/stdtypes.html#bytearray

exercises/practice/reverse-string/.articles/performance/code/Benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ def reverse_map(text):
100100
'reversed builtin', 'map and join']
101101
labels = row_headers
102102

103-
# Empty dataframe will be filled in one cell at a time later
103+
# Empty dataframe will be filled in one cell at a time later.
104104
df = pd.DataFrame(np.nan, index=row_headers, columns=col_headers)
105105

106-
# Function List to Call When Timing
106+
# Function List to Call When Timing.
107107
functions = [reverse_slice, reverse_iterate_and_prepend, reverse_range, reverse_half_swap, reverse_list_reverse,
108108
reverse_reversed, reverse_map]
109109

0 commit comments

Comments
 (0)