3 ms·
In Python, a function that makes and returns a copy would be idiomatically named shuffled(). Consider sorting: xs.sort() # in-place ys = sorted(xs
by int_19h 5y ago
In Python, a function that makes and returns a copy would be idiomatically named shuffled(). Consider sorting:
xs.sort() # in-place
ys = sorted(xs) # copy
As for functions returning the object - I think it's a hack around the absence of direct support for such repetition in the language itself. E.g. in Object Pascal, you'd write:
with array do
begin
append(A);
append(B);
sort;
end;
Or better yet, in Smalltalk:
array append(A); append(B); sort.
https://en.wikipedia.org/wiki/Method_cascading https://en.wikipedia.org/wiki/Method_cascading
- igouy 5y agoAlso https://dart.dev/guides/language/language-tour#cascade-notation https://dart.dev/guides/language/language-tour#cascade-notat...