Replies: 1 comment 2 replies
-
Actually if we had string longestLine = text.split("\n").maxElement(line => line.strip.length);
// docs:
string longestLine = [argmax(line.strip.length) line for line in text.split("\n")]; |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
There's an
argmax
list comprehension on the main page:I find it hard to understand. Shouldn't a list comprehension conceptually generate an array rather than a single value? Normally
arr.argmax
should return the index of the element inarr
with the largest value? So why doesargmax
take a line length as its argument not an array? And why is there a trailingline
after that? I find it clearer to write:Perhaps the named algorithms could support trailing algorithm syntax instead:
Also a list comprehension could produce a range and the algorithm suffix could just be a range function rather than built-in. Then any custom function could be used.
Beta Was this translation helpful? Give feedback.
All reactions