diff --git a/README.md b/README.md index 2fcd568..a71988b 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Welcome everyone to contribute to this project! ## Tool List: +- [acronym.py](https://github.com/Henry-Jia/python-tools/blob/master/acronym.py): Calculate a given string acronym - [age.py](https://github.com/Henry-Jia/python-tools/blob/master/age.py): compute the age for a person - [body_mass_index_GUI.py](https://github.com/Henry-Jia/python-tools/blob/master/body_mass_index_GUI.py): create body mass index calculated GUI by Python - [bot/bot.py](https://github.com/Henry-Jia/python-tools/blob/master/bot/bot.py): simple telegram bot diff --git a/acronym.py b/acronym.py new file mode 100644 index 0000000..cf30e90 --- /dev/null +++ b/acronym.py @@ -0,0 +1,21 @@ +import argparse +import re + +def abbreviate(words: str) -> str: + """ + :param str sentence: Given sentence to abbreviate + :rtype: bool + """ + pre = re.sub('[^A-Za-z ]', '', words.replace('-', ' ')) + return re.sub('[^A-Z]', '', pre.lower().title()) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--text",'-t', help="A text to be converted to its acronym.") + args = parser.parse_args() + + if args.text: + print(f'Your acronym is: {abbreviate(args.text)}') + else: + parser.print_help()