Files
python/exercises/practice/reverse-string/.approaches/additional-approaches/snippet.txt
BethanyG 93744302aa [Reverse String]: Add Approaches, Performance, and Unicode Articles (#3609)
* Added approaches and articles for reverse-string.

* Added code snippets for each approach.

* remaned files to silence configlet.

* renamed article snippets to .md to satisfy configlet.

* Apply suggestions from code review

Therefor != Therefore.  TIL.
Added missing link, so should no longer be broken.

* Added more on the downfalls and gotchas of unicode.

* Wrapping this up for now.

* Deleted the Unicode directory for now.
2025-02-14 18:32:13 -08:00

8 lines
413 B
Plaintext

given, output = bytearray(text.encode("utf-8")), bytearray(len(given))
index, LENGTH_MASK = 0, 0xE0 # 0b11110000 or 224
while index < len(given):
seq_len = not(given[index] >> 7) or (given[index] & LENGTH_MASK).bit_count()
location = index + seq_len +1
output[-location:-index or None] = given[index:index + seq_len]
index += seq_len
return output.decode("utf-8")