diff options
| author | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2021-02-10 09:57:23 -0800 |
|---|---|---|
| committer | Tyler Wardhaugh <tyler.wardhaugh@gmail.com> | 2021-02-12 09:31:25 -0800 |
| commit | dc48cb570de7841f7af41ba6e81ef64007c8059e (patch) | |
| tree | dd2217c742345d56926d8f57be3bcf51a40f3dfb /challenge-099/tyler-wardhaugh/python/ch-1.py | |
| parent | 49cab280781c426e997c691635fce821977d8439 (diff) | |
| download | perlweeklychallenge-club-dc48cb570de7841f7af41ba6e81ef64007c8059e.tar.gz perlweeklychallenge-club-dc48cb570de7841f7af41ba6e81ef64007c8059e.tar.bz2 perlweeklychallenge-club-dc48cb570de7841f7af41ba6e81ef64007c8059e.zip | |
Ch99 (Python): Tasks 1 & 2
Diffstat (limited to 'challenge-099/tyler-wardhaugh/python/ch-1.py')
| -rwxr-xr-x | challenge-099/tyler-wardhaugh/python/ch-1.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-099/tyler-wardhaugh/python/ch-1.py b/challenge-099/tyler-wardhaugh/python/ch-1.py new file mode 100755 index 0000000000..99cab7c794 --- /dev/null +++ b/challenge-099/tyler-wardhaugh/python/ch-1.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 +"""Challenge 99, Task 1""" + +import sys +from fnmatch import fnmatch + + +DEFAULT_INPUT = ('abcde', 'a*e') + + +def pattern_match(string, pattern): + """Return true if pattern p matches string s, according to glob rules.""" + return fnmatch(string, pattern) + + +def main(args=None): + """Run the task""" + if args is None: + args = sys.argv[1:] + + s, p = args[0:1] if args else DEFAULT_INPUT + if pattern_match(s, p): + print(1) + else: + print(0) + + +if __name__ == '__main__': + sys.exit(main()) |
