Skip to main content

Find common prefix of several `string`s, tuples of string, or other nested structure, recursively by default.

Project description

k3pattern

Action-CI Build Status Documentation Status Package

Find common prefix of several strings, tuples of string, or other nested structure, recursively by default.

k3pattern is a component of pykit3 project: a python3 toolkit set.

Find common prefix of several string, tuples of string, or other nested structure, recursively by default. It returns the shortest prefix: empty string or empty tuple is removed.

Install

pip install k3pattern

Synopsis

import k3pattern

k3pattern.common_prefix('abc', 'abd')                   # 'ab'
k3pattern.common_prefix((1, 2, 'abc'), (1, 2, 'abd'))   # (1, 2, 'ab')
k3pattern.common_prefix((1, 2, 'abc'), (1, 2, 'xyz'))   # (1, 2); empty prefix of 'abc' and 'xyz' is removed
k3pattern.common_prefix((1, 2, (5, 6)), (1, 2, (5, 7))) # (1, 2, (5,) )
k3pattern.common_prefix('abc', 'abd', 'abe')            # 'ab'; common prefix of more than two

Author

Zhang Yanpo (张炎泼) drdr.xp@gmail.com

Copyright and License

The MIT License (MIT)

Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com

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

k3pattern-0.1.0.tar.gz (2.9 kB view hashes)

Uploaded Source

Built Distribution

k3pattern-0.1.0-py3-none-any.whl (4.5 kB view hashes)

Uploaded Python 3

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