Skip to main content

Converts any base-10 integer into its corresponding alphabet form, and vice versa

Project description

num2alpha

Description

This Python script converts any base-10 integer into its "alphabetical number" counterpart. For example, 1 is a, 26 is z, and 28 is ab. This alphabetical number order is exactly what you find in the column name of most modern spreadsheet apps.

This script can also decode an alphabetical number and return its integer order in base-10. For instance, the spreadsheet column AXY is counted as the 1325-th column of the spreadsheed, and the string helloworld equals to 44580442473324.

Dependencies

This project depends on no third-party/external Python module. All modules required by num2alpha are already provided by the Python Standard Library.

Installation

num2alpha is available for download through Python Package Index (PyPI). Run the following command in your operating system via the terminal:

python -m pip install num2alpha

Usage

Import the num2alpha module as you would other modules.

import num2alpha as n2a

Then you can convert alphabet sequences to their respective numerical order in base-10 using the function alpha_to_number(). This function is case-insensitive. Therefore, alpha_to_number('abc') will yield the same result as alpha_to_number('ABC') as well as alpha_to_number('aBc').

n2a.alpha_to_number('a')
# returns 1

n2a.alpha_to_number('z')
# returns 26

n2a.alpha_to_number('aa')
# returns 27

n2a.alpha_to_number('ab')
# returns 28

n2a.alpha_to_number('python')
# returns 201883748

To do the otherwise, i.e., converting numbers to their respective alphabet forms, use the function number_to_alpha(). Please only pass base-10 integers greater than 0 into it. If you pass a floating number or other non-integer types into it, TypeError will be raised.

The return string will be in the form of [a-z] (in lowercase).

n2a.number_to_alpha(1)
# returns 'a'

n2a.number_to_alpha(2)
# returns 'b'

n2a.number_to_alpha(26)
# returns 'z'

n2a.number_to_alpha(27)
# returns 'aa'

n2a.number_to_alpha(2025)
# returns 'byw'

n2a.number_to_alpha(1234567890)
# returns 'cywoqvj'

If you are unsure about the type of data you are dealing with, you can use autoconvert() function to automatically determine whether the variable passed is a string of alphabetical characters or a base-10 integer. This function will then convert the passed argument accordingly.

n2a.autoconvert(123)
# returns 'ds'

n2a.autoconvert('helloworld')
# returns 44580442473324

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

num2alpha-1.0.1.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

num2alpha-1.0.1-py3-none-any.whl (29.7 kB view details)

Uploaded Python 3

File details

Details for the file num2alpha-1.0.1.tar.gz.

File metadata

  • Download URL: num2alpha-1.0.1.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for num2alpha-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cb295c44f302441daf47bfd115c431693ba00cd09987b0ede4dc80e93def04e9
MD5 f58540034efa00e396c2678fcff87cb4
BLAKE2b-256 c5ab2ce8986687906df439a95c0efd86d80e195d6af9003f9a7131f26e5b9323

See more details on using hashes here.

File details

Details for the file num2alpha-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: num2alpha-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 29.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for num2alpha-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 81a87c434a7878db9239be20e44dd2ab5dc57c4d2a013d5b782391d51d649a09
MD5 01dd12eec9139d64741459ac1269faad
BLAKE2b-256 04caa06cfe77445bd656921230ef8c0c8629e614b8335e58d8c6fc4045de8992

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