Skip to main content

Text sorting function for the Czech language

Project description

This is a pure-Python library Czech-language albhabetical sorting.

Quick Use

From Python:

>>> import czech_sort

>>> czech_sort.sorted(['sídliště', 'shoda', 'schody'])
['shoda', 'schody', 'sídliště']

>>> sorted(['sídliště', 'shoda', 'schody'], key=czech_sort.key)
['shoda', 'schody', 'sídliště']

On the command line:

$ python -m czech_sort < file.txt
shoda
schody
sídliště

Why another sorting library?

To sort Python strings in the Czech language, there are three other options:

  • Use PyICU. This can sort really well, and do all kinds of wonderful, standards-compliant Unicode things. Perfect for publication-quality results. Unfortunately, ICU can be a major pain to install, making it overkill if you just want to sort a list of strings.

  • Set the locale, then use locale.strxfrm. (Yes, strxfrm! Try saying that ten times fast!) This depends on the Czech POSIX locale being available, so it’s hardly portable.

  • Just use Python’s built-in string sort. This sorts lexicographically by Unicode codepoints. It might be good enough for you? Maybe?

Scope

The czech-sort library is a compromise. It should give you good results in the 99% case.

Do not use this if you need proper sorting of symbols, non-Latin scripts, or diacritics other than Czech/Slovak.

Any other deviation from the relevant standard, ČSN 97 6030, should be considered a bug. However, neither the author nor the community at large have access to the standard, which makes finding such bugs somewhat difficult.

Full API

czech_sort.*sorted*(iterable)

Takes an iterable of strings, and returns a list of them, sorted.

czech_sort.*key*(s)

Returns a sort key object for a given string.

Compatibility

The czech-sort library can be used with Python 2.6+ and 3.3+.

Under Python 2, it only accepts unicode strings.

Installation

Install this into your virtualenv by running:

pip install czech-sort

Contribute

Bug reports and comments are welcome at Github.

Patches are also welcome! Source code is hosted at Github:

$ git clone github.com/encukou/czech-sort

To run the included tests:

$ pip install pytest
$ python -m pytest

If you would like to contribute, but are confused by the above, then please e-mail encukou at gmail dot com.

License

The project is licensed under the MIT license. May it serve you well.

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

czech-sort-0.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

czech_sort-0.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file czech-sort-0.1.tar.gz.

File metadata

  • Download URL: czech-sort-0.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for czech-sort-0.1.tar.gz
Algorithm Hash digest
SHA256 8d2e5b705b8b4a0304c19a32f4d7504cc68b21fccbf3ba8ab3d0dd81fa3db80f
MD5 fca752d520aab277ed733a0745e0e69a
BLAKE2b-256 fa402dfa58ba826caa1ae3715063a111528c951599b7282b1cb48dc5813e30ec

See more details on using hashes here.

File details

Details for the file czech_sort-0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for czech_sort-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e9ea230e2074b4d7357b96abd354fb0a69dd9ad102370dbf772ca70f6c0bebd
MD5 a80337fc39ae431d1a5ab19ff45734b4
BLAKE2b-256 355f3ff663bb9ba622e93606228799bd4f1deea66062b6e00bfe235dfc58d9db

See more details on using hashes here.

Supported by

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