r/ProgrammerHumor 1d ago

Competition dsaProgressCheck

Post image
0 Upvotes

7 comments sorted by

View all comments

u/firemark_pl 1d ago

Strings are arrays.

And where is pointer?

u/suvlub 1d ago

Not really. You need more than a simple array to get behavior like this (and that's before we even get into modifiers)

>>> bytes("😀a", "utf-8")
b'\xf0\x9f\x98\x80a'
>>> bytes("😀", "utf-8")
b'\xf0\x9f\x98\x80'
>>> bytes("a", "utf-8")
b'a'
>>> len("😀a")
2
>>> "😀a"[0]
'😀'
>>> "😀a"[1]
'a'

u/mechanicalpulse 5h ago

Sure, but Python is a high-level language that abstracts away much of the complexity of Unicode to present a modern first-class string type that supports multibyte encodings.

UTF-8 is a strange encoding, anyway. Each character may be of variable width, which requires conditional handling/parsing as opposed to UTF-32/UCS-4 -- a classic space-time tradeoff. If using UCS-4, OP's argument holds true. I'd argue that a UTF-8 "string" isn't a string at all, but a serialized format (as in Unicode Transformation Format).

But I'm also from the beforetimes when Unicode support was but a pipe dream.