From 71630d21995076973073ae5a9a43afd0d0c9241c Mon Sep 17 00:00:00 2001 From: Joao Luiz Date: Thu, 24 Oct 2019 22:50:36 -0300 Subject: [PATCH 1/2] Create Acronym.py: Convert Text to its Acronym --- acronym.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 acronym.py 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() From a3e70143898f883262884cd65f5428657bae0720 Mon Sep 17 00:00:00 2001 From: Joao Luiz Date: Thu, 24 Oct 2019 22:57:10 -0300 Subject: [PATCH 2/2] Add Acronym.py to README.md --- README.md | 1 + 1 file changed, 1 insertion(+) 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