Learn Python Coding
40.9K subscribers
714 photos
37 videos
24 files
526 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
In Python 3.15, a single asterisk replaces nested loops. 🐍✨

Previously, to flatten a list, you would write:

rows = [[1, 2], [3], [4, 5]]

flat = [x for row in rows for x in row]


Now, you can simply use:

flat = [*row for row in rows]
# [1, 2, 3, 4, 5]


A double asterisk merges dictionaries: πŸ“¦

configs = [
{"debug": False, "timeout": 10},
{"timeout": 30},
]

config = {**part for part in configs}
# {'debug': False, 'timeout': 30}


When keys overlap, the last value wins – this is convenient for combining settings from multiple sources. βš™οΈ

Unpacking removes one level of nesting. In Python 3.14, this syntax within comprehensions will raise a SyntaxError. 🚫

https://peps.python.org/pep-0798/

#Python #Python315 #Programming #CodingTips #TechNews #Developer

✨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
❀7
🚨 SURPRISE ALERT! 🚨

Stop paying full price on Udemy. Seriously. πŸ’Έ

I built a bot that hunts down 100% FREE Udemy coupons 24/7 β€” while you sleep, eat, or scroll. 🎯

Here's the magic:

πŸ“š Mini App catalog β€” every active free coupon in one place
πŸ”” Auto-push β€” new courses land straight in your chat
πŸ“’ Live channel β€” never miss a deal

Why it matters?
Most people pay $200+ for courses you can grab for $0 β€” if you know where to look. Now you have a bot that does the looking for you. ⚑

πŸŽ“ Try it now: https://t.iss.one/UdemySybot?start=adsun

Your future self (and your wallet) will thank you. πŸ’œ
❀1
πŸ—‚ 500+ Cheat Sheets on Machine Learning

This repository contains materials on virtually everything: from basic algorithms and mathematics to neural networks, transformers, and advanced Deep Learning.

Each cheat sheet includes theory, formulas, Python examples, and tips on how to apply them.

β›“ You can find it here
https://github.com/gurovic/MLCheatSheets

#MachineLearning #DeepLearning #Python #DataScience #NeuralNetworks #AI

✨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
❀1
πŸš€ Django 6.1: Loading related data on demand, cascading deletion handled by the database, and a new email configuration.

The release was made on August 5th. Three major changes:

1. New Field Loading Modes πŸ“‚

FETCH_PEERS retrieves data for related objects from the same QuerySet when accessing an un-loaded field. This helps combat the N+1 problem:
from django.db import models

books = Book.objects.fetch_mode(models.FETCH_PEERS)

for book in books:
print(book.author.name)

In this example, Django executes two queries: one for the books and one for their authors.

The FETCH_RAISE mode raises an exception instead of performing an implicit query – useful for detecting unexpected database accesses.

2. Deletion at the Database Level πŸ—‘

For ForeignKey.on_delete, the options DB_CASCADE, DB_SET_NULL, and DB_SET_DEFAULT are now available. The logic is handled directly by the database using SQL ON DELETE.

Note: DB_CASCADE does not trigger pre_delete and post_delete signals.

3. Multiple Email Backends πŸ“§

The MAILERS configuration allows you to define different connections using a dictionary, and you can select the desired connection when sending emails using the using parameter.

Before upgrading, check your database versions: you need PostgreSQL 15+, MySQL 8.4+, MariaDB 10.11+, or SQLite 3.37+.

πŸ”— https://www.djangoproject.com/weblog/2026/aug/05/django-61-released/

#Django #Python #WebDevelopment #Django61 #Backend #TechNews

✨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
❀2
Why regular expressions can hang on a simple string
Even a short string can cause a regular expression to take seconds or minutes to execute. The reason is catastrophic backtracking, where the engine tries a huge number of matching possibilities.
Let's look at an example:
import re

pattern = re.compile(r"(a+)+$")

text = "a" * 18 + "!"

print(bool(pattern.fullmatch(text)))

Output:
False

The expression (a+)+$ looks simple, but the problem lies in the nested quantifiers (a+)+. When the engine encounters the !, the match fails. However, before giving up, it tries various ways to distribute the a characters among the repetitions.
The number of possibilities grows rapidly with the length of the string. Let's check the execution time:
import re
from time import perf_counter

pattern = re.compile(r"(a+)+$")

for size in (10, 12, 14, 16, 18):
text = "a" * size + "!"

start = perf_counter()
pattern.fullmatch(text)
elapsed = perf_counter() - start

print(size, f"{elapsed:.6f} сСк.")

The time depends on the processor and the version of Python, but for this pattern, you'll see an exponential increase in execution time as the number of a characters increases. This is dangerous when processing user input or external data.
If you need to check if a string consists only of a characters, nested repetitions are not necessary:
pattern = re.compile(r"a+")

print(bool(pattern.fullmatch("aaaa")))
print(bool(pattern.fullmatch("aaaa!")))

Output:
True
False

But not every problematic pattern can be simplified so easily. Starting with Python 3.11, the re module supports atomic groups (?x).
They prevent the engine from backtracking inside a successfully matched group to try other possibilities:
import re

pattern = re.compile(r"(?x)a+!$")

print(bool(pattern.fullmatch("aaaa")))
print(bool(pattern.fullmatch("aaaa!")))

Output:
True
False

The group (?x)a+ fixes the captured sequence of characters. The engine can no longer redistribute them within the group, which eliminates catastrophic backtracking in this example.
In Python 3.11, possessive quantifiers are also available: *+, ++, and ?+. They do not release captured characters during backtracking:
pattern = re.compile(r"(a++)+$")

print(bool(pattern.fullmatch("aaaa")))
print(bool(pattern.fullmatch("aaaa!")))

Output:
True
False

Here, a++ is equivalent to (?x)a+, so nested repetitions no longer cause exponential backtracking.
However, possessive quantifiers can change the matching result:
import re

print(bool(re.fullmatch(r"a+a", "aa")))
print(bool(re.fullmatch(r"a++a", "aa")))

Output:
True
False

A regular a+ might return one character for the last a. The quantifier a++ does not allow this.
Let's compare the performance of all three options using timeit:
import re
import timeit

text = "a" * 18 + "!"

patterns = {
"nested": re.compile(r"(a+)+$"),
"atomic": re.compile(r"(?x)a+!$"),
"possessive": re.compile(r"(a++)+$"),
}

for name, pattern in patterns.items():
elapsed = timeit.timeit(
lambda: pattern.fullmatch(text),
number=10
)

print(name, f"{elapsed:.6f} сСк.")

Here, the total time for ten runs of each pattern is measured. It's useful to test strings that almost match the expression but contain an incorrect character at the end.
πŸ”₯ Ambiguous nested repetitions can cause exponential growth in execution time. Atomic groups and possessive quantifiers help limit backtracking, but only if their use preserves the necessary matching logic.
❀2
πŸ“ Cheat sheet for Python:

Higher-order functions:

πŸ”Ή map() - applies a function to each element
πŸ”Ή filter() - selects elements based on a condition
πŸ”Ή reduce() - sequentially combines elements into a single value

These functions help to process collections concisely and perform data transformations.

#Python #Programming #Coding #HigherOrderFunctions #DataProcessing #TechTips

✨ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk

⭐️ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
❀4
Please open Telegram to view this post
VIEW IN TELEGRAM
❀1