Skip to main content

Simple command-line anagram solver

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ruben-anagram-solver-0.1.0.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file ruben-anagram-solver-0.1.0.tar.gz.

File metadata

  • Download URL: ruben-anagram-solver-0.1.0.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for ruben-anagram-solver-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e1ed1c673b2e89d29a87af0d145c72d8c2e0ca84eb551bc22b9ae5b20e201aa6
MD5 49098087f6bec05fb5f8c448f8c26810
BLAKE2b-256 c28d489dd8114877bcb8ffb9989735d5261bb7144428c37cd35eda6d6c4d5e8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page