Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions acronym.py
Original file line number Diff line number Diff line change
@@ -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()