Skip to main content

Count unique characters in text or files

Project description

Char Counter

A Python CLI tool and library for counting unique characters in text strings or files.

Features

  • ✅ Count unique characters in text strings
  • ✅ Process text files
  • ✅ Priority system: --file takes precedence over --string
  • ✅ Comprehensive error handling
  • ✅ Can be used as CLI tool or Python library

Installation

pip install char-counter-alexxstep

Usage

Command Line Interface

Count unique characters in a string:

char-counter --string "abbbccdf"
# Output: 3

Count unique characters from a file:

char-counter --file path/to/file.txt

Priority rule - if both arguments provided, file takes precedence:

char-counter --string "ignored" --file data.txt
# Processes the file, ignores the string argument

As Python Library

from char_counter import count_unique_characters

# Count unique characters
result = count_unique_characters("abbbccdf")
print(result)  # Output: 3

# Characters that appear exactly once: a, d, f

What are "unique characters"?

A character is considered unique if it appears exactly once in the text.

Examples:

  • "abbbccdf" → 3 unique characters (a, d, f)
  • "aabbcc" → 0 unique characters (all repeat)
  • "abc" → 3 unique characters (all unique)

Development

Installation for Development

# Clone the repository
git clone https://git.foxminded.ua/python-web/task5_create_package.git
cd task5_create_package

# Install in editable mode with dev dependencies
pip install -e ".[dev]"

Running Tests

# Run all tests
python -m pytest tests/ -v

# Run with coverage
python -m pytest tests/ --cov=char_counter --cov-report=html

Code Quality

This project uses ruff for linting and formatting:

# Format code
uvx ruff format .

# Check and fix linting issues
uvx ruff check . --fix

Requirements

  • Python 3.8 or higher
  • No external dependencies for core functionality

License

MIT License - see LICENSE file for details.

Author

Oleksiy Stypanets (Alex Step)

Project Structure

task5_create_package/
├── src/
│   └── char_counter/
│       ├── __init__.py      # Package initialization
│       ├── counter.py       # Core counting logic
│       └── cli.py           # Command-line interface
├── tests/
│   ├── test_counter.py      # Unit tests for counter
│   └── test_cli.py          # Tests for CLI with mocks
├── pyproject.toml           # Project configuration
├── README.md                # This file
└── LICENSE                  # MIT License

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

char_counter_alexxstep-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

char_counter_alexxstep-0.1.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file char_counter_alexxstep-0.1.0.tar.gz.

File metadata

  • Download URL: char_counter_alexxstep-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for char_counter_alexxstep-0.1.0.tar.gz
Algorithm Hash digest
SHA256 05e4f4bb17e8dc9dc7079f7d44aa920ba356185e2ebddf0ef193800d33b5b787
MD5 6fdf2c1619bf951c2f478a237c241296
BLAKE2b-256 1d533abcc832c1a338a75f4b0d08af832124a05c6e3b503275e1c50dab9f2d60

See more details on using hashes here.

File details

Details for the file char_counter_alexxstep-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for char_counter_alexxstep-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 435482f7c81b7be51ad237884ff244ab114de521a277f8e55afe34efb52495f0
MD5 f6bf45e8e1021d621b30e947c7891141
BLAKE2b-256 4c39e5841222a966a0f114941450d381a48dce0ffdaaabb11cc99a773e565fa6

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