https://github.com/pykit3/k3pattern
Find common prefix of several `string`s, tuples of string, or other nested structure, recursively by default.
https://github.com/pykit3/k3pattern
pattern python
Last synced: 4 months ago
JSON representation
Find common prefix of several `string`s, tuples of string, or other nested structure, recursively by default.
- Host: GitHub
- URL: https://github.com/pykit3/k3pattern
- Owner: pykit3
- License: mit
- Created: 2021-08-05T06:55:39.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2025-08-28T12:37:48.000Z (9 months ago)
- Last Synced: 2025-09-22T16:10:54.252Z (8 months ago)
- Topics: pattern, python
- Language: Python
- Homepage: https://blog.openacid.com
- Size: 30.3 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# k3pattern
[](https://github.com/pykit3/k3pattern/actions/workflows/python-package.yml)
[](https://k3pattern.readthedocs.io/en/stable/?badge=stable)
[](https://pypi.org/project/k3pattern)
Find common prefix of several `string`s, 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
```python
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 (张炎泼)
# Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼)
[pykit3]: https://github.com/pykit3