Learn Python Coding
39.2K subscribers
648 photos
32 videos
24 files
412 links
Learn Python through simple, practical examples and real coding ideas. Clear explanations, useful snippets, and hands-on learning for anyone starting or improving their programming skills.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
Catch a useful trick for working with division in Python ๐Ÿ

divmod() takes two numbers and in a single operation returns a tuple with the quotient and remainder from the division ๐Ÿ“Š

#Python #Coding #Programming #Tech #Tips #Dev

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค3
Smart counting of elements using collections.Counter ๐Ÿ“Š

from collections import Counter

# Initial list with duplicate elements
logs = ["error", "info", "error", "warning", "error", "info"]

# 1. Instantly count the number of occurrences
count_dict = Counter(logs)
print(count_dict) # Counter({'error': 3, 'info': 2, 'warning': 1})

# 2. Get the most frequent elements (Top-2)
print(count_dict.most_common(2)) # [('error', 3), ('info', 2)]

# 3. Set math for counters
clicks_day1 = Counter(item=4, banner=2)
clicks_day2 = Counter(item=1, banner=5)
# Combine the results of two days in a single operation
print(clicks_day1 + clicks_day2) # Counter({'banner': 7, 'item': 5})

Forget about manual loops and dictionaries ๐Ÿšซ๐Ÿ”„

When you need to count the frequency of words in a text, the distribution of log types, or popular products in a store, developers usually create an empty dictionary and write a loop with a check if key not in dict: dict[key] = 1. The Counter class takes all this dirty work on itself and makes it as efficient as possible.

โ€” Automatic initialization: You no longer need to check if a key exists in the dictionary. If the element is not there, Counter will not throw a KeyError, but simply return 0. ๐Ÿ›ก๏ธ

โ€” Finding leaders without sorting: The most_common(k) method returns a list of the k most frequently occurring elements. Under the hood, Python uses optimized heap algorithms, which work much faster than a full dictionary sort via sorted(). ๐Ÿ†

โ€” Mathematical operations: You can add, subtract, intersect, and merge Counter objects. This turns them into a powerful tool for aggregating metrics and analytics from different data sources in a few lines of code. โž•โž–

#Python #DataScience #Coding #Programming #Automation #DevOps

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค5๐Ÿ”ฅ1
Python can make a dictionary immutable without copying data!

Usually, to protect configurations and the overall state, a copy of the dictionary is made, which creates unnecessary memory allocations.

safe = dict(config)

MappingProxyType creates a read-only proxy over a dictionary โ€” writing through it becomes impossible, but the data is not copied.

readonly["debug"] = True  # TypeError

At the same time, the proxy remains alive: if the original dictionary changes, the changes will automatically be reflected in the read-only view.

config["debug"] = True

This is especially useful for configurations, internal APIs, overall state, and data protection within libraries.

def get_settings():
return MappingProxyType(settings)

๐Ÿ”ฅ MappingProxyType allows you to provide a read-only view of the dictionary without copying and without the risk of mutation through the returned object.

#Python #Immutable #DataProtection #MappingProxyType #ProgrammingTips #NoCopy

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค2
The ternary operator in Python looks appealing, but it's easy to overdo it with it ::

'A' if s>=90 else 'B' if s>=80 else 'C' if s>=70 else 'F'

Just because the code can be compressed into one line, doesn't mean it's a good idea for readability.

When the logic starts to branch out (3+ conditions) โ€” the usual if-elif-else becomes much more understandable and easier to maintain.

It's better to leave the ternary operator for simple and short cases:
โ€ข compact expressions in comprehensions
โ€ข small lambda functions
โ€ข simple one-line returns

๐Ÿ’ก #Python #Coding #Programming #Developer #SoftwareEngineering #CodeQuality

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค1
๐ŸŽ SPOTO Mid-Year Sale โ€“ Grab Your IT Certification Success Kit!

๐Ÿ”ฅ Whether you're prepping for #Python, #AI, #Cisco, #PMI, #Fortinet, #AWS, #Azure, #Excel, #Comptia, #ITIL, #Cloud or any other hot certification โ€“ SPOTO has your back with real exam dumps and hands-on training!

โœ… Free Resources:
ใƒปFree Python, Excel, Cyber Security, Cisco, SQL, ITIL, PMP, AWS courses: https://bit.ly/4alTSfk
ใƒปIT Certs E-book: https://bit.ly/49ub0zq
ใƒปIT Exams Skill Test: https://bit.ly/4dVPapB
ใƒปFree AI material and support tools: https://bit.ly/4elzcpl
ใƒปFree Cloud Study Guide: https://bit.ly/4u7sdG0

๐ŸŽ Join SPOTO Mid-Year Lucky Draw:
๐Ÿ“ฑ iPhone 17 ๐Ÿ›’ Free Order
๐Ÿ›’ Amazon Gift $100 ๐Ÿ“˜PMP/ AWS/ CCNA Course


๐Ÿ‘‰ Enter the Draw Now โ†’ https://bit.ly/4uN3lVt

๐Ÿ‘‰ Join Our IT Learning Community for free resources & support:
https://chat.whatsapp.com/FQOG04r9xSiIa2ElhaNUJU
๐Ÿ’ฌ Want exam help? Chat with an admin now:
https://wa.link/knicza

โฐ Mid-Year Deal Ends Soon โ€“ Don't Miss Out!
๐Ÿ“‚ Reminder on Python set โ€” set methods!

For example, add() adds an element to the set, update() combines several elements, and intersection() helps quickly find common values between data sets.

In the picture โ€” the main methods and operations for working with set: addition, removal, union, intersection, difference, and set checks.

Save it to not lose it!

#Python #SetMethods #Coding #DataScience #Programming #HelloEncyclo

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
10 GitHub Repositories for Web Development in Python ๐Ÿ

Explore the best Python web development repositories for building APIs, full-stack web apps, dashboards, machine learning demos, internal tools, and interactive Python-based user interfaces. ๐Ÿ”ฅ

https://www.kdnuggets.com/10-github-repositories-for-web-development-in-python

#Python #WebDevelopment #GitHub #Coding #API #Tech

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
Guessing numbers

This project for beginners in Python is a fun game that generates a random number (within a certain range) that the user must guess after receiving hints.

For each incorrect guess, the user receives additional hints, but at the cost of reducing their overall score.

๐Ÿ’ก๐Ÿ๐ŸŽฎ #Python #Coding #Beginners #Game #Learning #Tech

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค2
I often see people say that it's impossible to enter the IT field without expensive courses.

However, there's a huge amount of high-quality materials available for free:

๐Ÿ“š Computer Science
https://github.com/ossu/computer-science

๐Ÿ“š Data Structures & Algorithms
https://github.com/jwasham/coding-interview-university

๐Ÿ“š System Design
https://github.com/donnemartin/system-design-primer

๐Ÿ“š Web Development
https://github.com/TheOdinProject/curriculum

๐Ÿ“š Frontend / Backend / DevOps / Cloud
https://github.com/kamranahmedse/developer-roadmap

๐Ÿ“š Data Engineering
https://github.com/DataTalksClub/data-engineering-zoomcamp

๐Ÿ“š Machine Learning & AI
https://github.com/microsoft/ML-For-Beginners

๐Ÿ“š MLOps
https://github.com/DataTalksClub/mlops-zoomcamp

๐Ÿ“š Cybersecurity
https://github.com/OWASP/CheatSheetSeries

๐Ÿ“š Linux
https://github.com/trimstray/the-book-of-secret-knowledge

๐Ÿ“š Free Programming Books
https://github.com/EbookFoundation/free-programming-books

If you have internet and a bit of free time, you can learn computer science, algorithms, system design, DevOps, clouds, security, and machine learning for free.

The problem now isn't a lack of information. The problem is regularly opening these repositories and actually working on them.

#FreeLearning #ITCareer #CodingResources #TechEducation #OpenSource #DevCommunity

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค1
Please open Telegram to view this post
VIEW IN TELEGRAM
โค1
How to create an object from a dictionary with dot access โ€” without classes and dataclasses?

When you're working with JSON, configurations, or APIs, constant access via dict['key'] clutters the code and worsens readability:

data = {"host": "localhost", "port": 5432}
data["host"]

SimpleNamespace gives the same result, but with dot access:

cfg = SimpleNamespace(**data)
print(cfg.host)

In this case, the object remains dynamic, and you can add fields:

cfg.debug = True

However, the keys must be valid attribute names, and this only works for flat dictionaries (nesting is not converted).

๐Ÿ”ฅConvenient for prototyping, testing, and simple data.

#Python #DataStructures #SimpleNamespace #CodingTips #DevTools #Programming

โœจ Join Best TG Channels https://t.me/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A

๐Ÿš€ Level up your AI & Data Science skills with HelloEncyclo โ€” a growing all-in-one platform featuring hands-on courses in LLMs, Deep Learning, MLOps, Data Engineering, and more.
โœ… 13 courses live + 40+ coming soon
๐ŸŽฏ One access, lifetime updates
๐Ÿ”‘ Use code: PRESALE-BOOK-WAVE-2GFG
๐Ÿ‘‰ https://helloencyclo.com/?ref=HUSSEINSHEIKHO
โค2