Alexey Vyskubov’s Post

Let's look at Python (in)consistency: >>> s='a' >>> s.split()==s.split(' ') True >>> s='' >>> s.split()==s.split(' ') False How come? The point here -- let me quote the docs -- "If sep is not specified or is None, a different splitting algorithm is applied". If separator is not specified, empty strings at the beginning and the end of the result are discarded, so while ''.split(' ') is [''], ''.split() is []. #Python #gotcha

...and let me quote "import this": "Special cases aren't special enough to break the rules."

Other annoying things about Python strings: - characters are length 1 strings and not a type of their own - "s in t" means "s is a substring of t" for strings but "s is a member of t" for tuples, sets etc. - "s < t" means "s precedes t lexicographically" for strings, tuples, etc. but "s is a proper subset of t" for sets

Python is primary driver for ml dev. Given undeterminism is mandatory for development of underteministic systems such as LLMs.

If you think python is inconsistent you should try JavaScript, to see what inconsistent really is

Like
Reply

Another funny (yet documented) case is " foo ".split(maxsplit=0) producing ['foo ']

See more comments

To view or add a comment, sign in

Explore content categories