swap_case doesn't correctly handle non-ASCII letters · Issue #3847 · TheAlgorithms/Python · GitHub
Skip to content

swap_case doesn't correctly handle non-ASCII letters #3847

Description

@frankschmitt

The strings/swap_case implementation works only for ASCII letters (since it uses the incomplete regex [^a-zA-Z] to check whether a given characters is a letter). If you provide it with a non-ASCII letter, it will happily swap it and also return the unchanged version.

Example:

➜ strings git:(master) python3 swap_case.py
Please input sentence:This is broken: äü
tHIS IS BROKEN: ÄäÜü

The solution is pretty straightforward - it shouldn't use a regular expression at all, but rely on the built-in Python functions (as it partially already does).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions