Skip to main content

Anagram Solver

Build Status PyPI GitHub

Simple anagram solver.

Currently only English is supported, but it could be extended to support other languages. The main difficulty would be finding a systematic way to obtain lists of valid words for multiple languages.

Installation

Install as usual:

pip install ruben-anagram-solver

You may wish to create a virtual environment beforehand.

Usage

Run the program using the following command:

ruben-anagram-solver

Using the program is extremely simple:

Enter string: cchikne
['check-in', 'chicken']

How It Works

Since an anagram of some word is just some rearrangement of the word's letters, two words are anagrams of each other if they are same when the order (and possibly case) of the letters is ignored. To check this, the idea was to convert each of the two words to some "order-insensitive" representation and compare this. Such a representation could be simply the letters sorted (e.g. ['c', 'c', 'e', 'h', 'i', 'k', 'n'] for "chicken") or a count of each letter in the word (e.g. {('n', 1), ('h', 1), ('c', 2), ('e', 1), ('i', 1), ('k', 1)}). I also decided to ignore case (by first converting the word to lower case) and ignore non-alphanumeric characters (by removing them from the word).

The exact steps are as follows:

  1. Read a list of English words.
  2. Convert each word to its order-insensitive representation (as described above).
  3. Create a dictionary where each key is an order-insensitive representation (e.g. {"a": 1, "b": 1, "t": 1}) and each value is the set of words that correspond to that order-insensitive representation (e.g. {"bat", "tab"}).
    • This is to make lookups more efficient, should the program be extended to allow multiple lookups.
  4. Input an anagram from the user.
  5. Convert the anagram to its order-insensitive representation.
  6. Look this up in the dictionary to obtain the set of words corresponding to the anagram's order-insensitive representation.
  7. Output this set of words.

Release files for ruben-anagram-solver 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ruben-anagram-solver 0.1.0
File Size Uploaded
ruben-anagram-solver-0.1.0.tar.gz 3.7 kB Details

Release files / ruben-anagram-solver-0.1.0.tar.gz

Download URL ruben-anagram-solver-0.1.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e1ed1c673b2e89d29a87af0d145c72d8c2e0ca84eb551bc22b9ae5b20e201aa6
BLAKE2b-256 checksum
How to use checksums
c28d489dd8114877bcb8ffb9989735d5261bb7144428c37cd35eda6d6c4d5e8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page