Bring Your Logic using Python
342 subscribers
109 photos
1 video
4 files
544 links
Logic building using Python : Materials, links, e-books and Code snippets
Download Telegram
Did you know that #Python's round() built-in accepts a negative number that lets you rounds up to the next 10, 100, 1000, ... ? 🐍🤯
#Python set operations are powerful, concise and elegant:
Download a YouTube video with #Python in 6 lines of code!

🐍🔥
Common #Python #interview question:
How to flatten a list of lists (several nested levels)?

Seems itertools.chain only goes one level deep, so let's use some recursion here.
#Python default argument values are evaluated once so mutability can bite you, use "None" instead.
What is this if name == "__main__": at the end of a #Python script?

It's typically used to include code that ONLY should run if the module / script is called directly and NOT upon importing it.

Example:
#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👇🏻
#Python's print() built-in is more powerful than you might think
#Python has lots of great packages. Here are just a few:

🐍Textual - TUI
🤖Playright - Web testing
📄OpenPyXL - Read / Write Excel
🌐ReportLab - Create PDFs
🐍Numpy - Mathematics
🐼Pandas - Data Analysis
👓OpenCV - Computer vision
🔦PyTorch - ML
🔥Kivy - Mobile apps
#Python Pop Quiz 🐍❓

What does this code do?

A) NameError
B) SyntaxError
C) prints out None
D) What is this madness?