Bring Your Logic using Python
341 subscribers
109 photos
1 video
4 files
544 links
Logic building using Python : Materials, links, e-books and Code snippets
Download Telegram
#Snippet
Useful constants in #python

Using #Python's calendar module + the enumerate built-in to make a mapping of month names -> numbers

>>> import calendar
>>> MONTH_NAMES_TO_NUMBERS = {
... v: k for k, v in enumerate(calendar.month_abbr[1:], start=1)
... }

>>> MONTH_NAMES_TO_NUMBERS
{'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}
How to send a tweet with #Python and TweePy in under 10 lines of code

🐍🔥

For more information, refer the Twitter thread given below👇🏻
Invert binary tree in Python

Binary tree
is a data structure and one of the simplest form of trees. You might have heard about people complaining that during interviews they are asked to invert a binary tree.

It may sound like something difficult, but this article shows a really simple solution using recursion.

https://bmwlog.pp.ua/invert-binary-tree-in-python/
In this article, we focus on patterns that can make the code more robust, understandable, and overall easier to handle. You will see how simple improvements can lead to more reusable code and fewer bugs.

https://zerowithdot.com/improve-data-science-code/