DEV Community

Discussion on: Rust, Iterators, and Skill Regression

Collapse
rhymes profile image
rhymes
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')}")