mathspp
  • Blog
    • Pydon'ts
    • Problems
    • TIL
    • Twitter threads
  • Books
  • Talks
  • Trainings
    • Advanced iteration
    • Python for scripting and automation
    • Rust for Python developers
  • Courses
  • About
Link blog

The fastest way to detect a vowel in a string

by Austin Z. Henley on 24-06-2025 22:07 (via)

In this article, Austin goes over 11 creative ways to check if there is a vowel in a string. After a lot of acrobatics and creative snippets of code, Austin found out that a regex search using the module re was faster than any other Python solution that Austin wrote...

And then the internet stepped in, and the (so far) fastest solution was found:

def loop_in_perm(s):  # best
        for c in "aeiouAEIOU":
            if c in s:
                return True
        return False

What's fun is that a similar function, with “the loops reversed” had already been considered and was only performing mediocrely. This is the mediocre version:

def loop_in(s):  # similar to best but mediocre
    for c in s:
        if c in "aeiouAEIOU":
            return True
    return False

Previous link Next link

Check out codegolf.stackexchange.com if you want to solve programming puzzles, but with a twist.

mathspp
  • Blog
    • Pydon'ts
    • Problems
    • TIL
    • Twitter threads
  • Books
  • Talks
  • Trainings
    • Advanced iteration
    • Python for scripting and automation
    • Rust for Python developers
  • Courses
  • About