Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

A Pure-Python implementation of the tr algorithm

Project Description


This module is a Python implementation of the tr algorithm.

tr(string1, string2, source, option=’‘)

If not given option, then replace all characters in string1 with the character in the same position in string2.

Following options are available:

Replace all complemented characters in string1 with the character in the same position in string2.
Delete all characters in string1.
Squeeze all characters in string1.
Squeeze all the characters in string2 besides “c” replacement.
Delete all characters in string1. Squeeze all characters in string2.
Delete all complemented characters in string1.
  • <unicode> string1
  • <unicode> string2
  • <unicode> source
  • <basestring> option
  • <unicode> translated_source


  • If Python2.x, the type of paramaters (string1, string2 and source) must be unicode.
  • If Python3.3 or later, the type of paramaters (string1, string2 and source) must be str.


pip install python-tr



from tr import tr
tr(u'bn', u'cr', u'bunny')
# => u'curry'
tr(u'n', '', u'bunny', 'd')
# => u'buy'
tr(u'n', u'u', u'bunny', 'c')
# => u'uunnu'
tr(u'n', u'', u'bunny', 's')
# => u'buny'
tr(u'bn', '', u'bunny', 'cd')
# => u'bnn'
tr(u'bn', u'cr', u'bunny', 'cs')
# => u'brnnr'
tr(u'bn', u'cr', u'bunny', 'ds')
# => u'uy'

Python3.3 or later

from tr import tr
tr('bn', 'cr', 'bunny')
# => 'curry'
tr('n', '', 'bunny', 'd')
# => 'buy'
tr('n', 'u', 'bunny', 'c')
# => 'uunnu'
tr('n', '', 'bunny', 's')
# => 'buny'
tr('bn', '', 'bunny', 'cd')
# => 'bnn'
tr('bn', 'cr', 'bunny', 'cs')
# => 'brnnr'
tr('bn', 'cr', 'bunny', 'ds')
# => 'uy'

Contributions are welcome.


0.1.2 (2016-03-11)

  • Fix transliteration bugs in no option bug

This bug is reported by id774. Many thanks.

0.1.1 (2015-02-11)

  • Fix metacharcter bug in squeeze

This bug is reported by Pierre Nugues. Many thanks.

0.1 (2014-11-24)

  • Improve processing speed slightly

0.0.1 (2014-07-10)

First release.

Release History

Release History

This version
History Node


History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
python-tr-0.1.2.tar.gz (3.8 kB) Copy SHA256 Checksum SHA256 Source Mar 11, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting