Apr-29-2019, 07:15 PM
Personally, I'm glad python doesn't let you modify builtin types. Javascript has that, and it makes reading through some libraries/frameworks quite painful, since you don't really know if they're using the standard Array.slice, or if Array.slice never existed and they added it, or if they just replaced the builtin Array.slice with their own custom version.
Especially since there's nothing string specific about this particular case. "begins" could just as easily apply to any iterable such as lists.
And also it's just a one-line function, really makes me glad it can't be augmented to all strings.
tl;dr: I'm glad this isn't valid:
Especially since there's nothing string specific about this particular case. "begins" could just as easily apply to any iterable such as lists.
And also it's just a one-line function, really makes me glad it can't be augmented to all strings.
tl;dr: I'm glad this isn't valid:
str.begins = lambda s, args: any(s.startswith(substr) for substr in args)