loading...

re: Rust, Iterators, and Skill Regression VIEW POST

FULL DISCUSSION
 
fn has_double(s: &str) -> bool {
    s.chars().zip(s.chars().skip(1))
        .any(|(a, b)| a == b)
}

This is so much clearer! Great article!

BTW in Python this is how I'd do it:

import operator


def has_double(s):
    return any(operator.eq(a, b) for a, b in zip(s, s[1:]))

if __name__ == '__main__':
    print(f"banana: {has_double('banana')}")
    print(f"apple: {has_double('apple')}")
code of conduct - report abuse