diff options
Diffstat (limited to 'challenge-012/lubos-kolouch/python/ch-2.py')
| -rw-r--r-- | challenge-012/lubos-kolouch/python/ch-2.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-012/lubos-kolouch/python/ch-2.py b/challenge-012/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..43788cde70 --- /dev/null +++ b/challenge-012/lubos-kolouch/python/ch-2.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +paths = ["/a/b/c/d", "/a/b/cd", "/a/b/cc", "/a/b/c/d/e"] +separator = "/" + +common_path = [] +for path in paths: + parts = path.split(separator) + if not common_path: + common_path = parts + else: + for i in range(len(common_path)): + if common_path[i] != parts[i]: + common_path = common_path[:i] + break + +print(f"The common directory path is: {separator.join(common_path)}") |
