Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Find the longest string

Rust

#![allow(unused)]
fn main() {
let words = vec!["cat", "elephant", "dog"];

let longest = words.iter().max_by_key(|w| w.len());
}

Python

words = ["cat", "elephant", "dog"]

longest = max(words, key=lambda w: len(w))