Skip to content

Refactor syllable.py to use set for thai_consonants_all #1087

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025

Conversation

allrob23
Copy link
Contributor

@allrob23 allrob23 commented Mar 29, 2025

What does this changes

Switches thai_consonants_all from a list to a set in pythainlp/util/syllable.py and simplifies its use in sound_syllable.

What was wrong

Its not wrong, but the original code used if i in list(thai_consonants_all) for membership checks, which was less efficient due to list’s O(n) lookup time.

How this fixes it

Using a set for thai_consonants_all cleans up the code to if i in thai_consonants_all, leverages set’s O(1) lookups for speed, and maintains identical logic with no downsides.

Your checklist for this pull request

  • Passed code styles and structures
  • Passed code linting checks and unit test

Copy link
Member

@wannaphong wannaphong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@bact bact added the refactoring a technical improvement which does not add any new features or change existing features. label Mar 30, 2025
wannaphong added a commit that referenced this pull request Mar 31, 2025
- PR Description: Refactor thai_consonants_all to Use set in syllable.py #1087  @allrob23
-  ThaiTransliterator: Select 1D CPU int64 tensor device #1089 @jkingd0n
@wannaphong wannaphong mentioned this pull request Mar 31, 2025
@wannaphong wannaphong merged commit a345f9e into PyThaiNLP:dev Mar 31, 2025
26 of 29 checks passed
@bact bact changed the title PR Description: Refactor thai_consonants_all to Use set in syllable.py Refactor syllable.py to use set for thai_consonants_all Mar 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring a technical improvement which does not add any new features or change existing features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants