๐ Reminder about Python map()!
map() โ a built-in function that applies the specified function to each element of an iterable object (list, tuple, set, etc.).
The picture shows the basic syntax, an example of use with lambda, and a typical case โ data transformation without a manual for loop.
Save it to quickly remember the syntax!
๐๐ป๐บ๏ธ #Python #Coding #Programming #LearnToCode #DevTips #Tech
map() โ a built-in function that applies the specified function to each element of an iterable object (list, tuple, set, etc.).
The picture shows the basic syntax, an example of use with lambda, and a typical case โ data transformation without a manual for loop.
Save it to quickly remember the syntax!
๐๐ป๐บ๏ธ #Python #Coding #Programming #LearnToCode #DevTips #Tech
โค7๐1
Why is enumerate() used in Python? ๐ค๐
It allows you to simultaneously obtain the value of an element and its index when iterating through a list. ๐โจ
This is more convenient and more readable than manually working with a counter. โ ๐
#Python #Coding #Programming #Dev #Tech #Code
โจ Join Best TG Channels
https://t.iss.one/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel
https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
It allows you to simultaneously obtain the value of an element and its index when iterating through a list. ๐โจ
This is more convenient and more readable than manually working with a counter. โ ๐
for i, item in enumerate(items):
print(i, item)
#Python #Coding #Programming #Dev #Tech #Code
โจ Join Best TG Channels
https://t.iss.one/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel
https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
โค4๐1๐1
Deep copying of objects with the copy module ๐๐ฆ
The link trap in Python ๐๐ณ๏ธ
When you assign a list to another variable (A = B) or make a regular slice (A = B[:]), Python doesn't physically copy the data. It simply creates a new reference to the same objects in memory. If the list contains other mutable objects (lists, dictionaries, custom classes), standard copying methods will only create a shallow copy. The copy module allows you to control this process.
โ Breaking the links: The deepcopy function recursively traverses the entire data structure and creates honest, independent duplicates for each nested element. This ensures that changes in the copy will not harm the original data. ๐๐
โ Safe state: The use of deep copying is critical when implementing design patterns (for example, Snapshot/Memento), creating game state backups, or when you pass complex configurations to functions that may modify them accidentally. ๐ก๏ธ๐พ
โ A sensible balance: It's worth remembering that deepcopy works slower and consumes more memory than shallow copying, as it spends resources on creating new objects and checking for cyclic references. Use it specifically when there are nested mutable containers within the structure. โ๏ธ๐ง
#Python #Programming #DeepCopy #Coding #Tech #Dev
โจ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
import copy
# Original list with nested structure
original = [[1, 2, 3], [4, 5, 6]]
# 1. Shallow copy
shallow = copy.copy(original)
shallow[0][0] = 'X'
# Oh no! Both lists have changed, because the nested list wasn't copied, but passed by reference
print(f"Original after shallow: {original}") # [['X', 2, 3], [4, 5, 6]]
# Restore the data
original = [[1, 2, 3], [4, 5, 6]]
# 2. Deep copy
deep = copy.deepcopy(original)
deep[0][0] = 'X'
# Everything is fine! Only deep has changed, the original remains untouched
print(f"Original after deep: {original}") # [[1, 2, 3], [4, 5, 6]]
The link trap in Python ๐๐ณ๏ธ
When you assign a list to another variable (A = B) or make a regular slice (A = B[:]), Python doesn't physically copy the data. It simply creates a new reference to the same objects in memory. If the list contains other mutable objects (lists, dictionaries, custom classes), standard copying methods will only create a shallow copy. The copy module allows you to control this process.
โ Breaking the links: The deepcopy function recursively traverses the entire data structure and creates honest, independent duplicates for each nested element. This ensures that changes in the copy will not harm the original data. ๐๐
โ Safe state: The use of deep copying is critical when implementing design patterns (for example, Snapshot/Memento), creating game state backups, or when you pass complex configurations to functions that may modify them accidentally. ๐ก๏ธ๐พ
โ A sensible balance: It's worth remembering that deepcopy works slower and consumes more memory than shallow copying, as it spends resources on creating new objects and checking for cyclic references. Use it specifically when there are nested mutable containers within the structure. โ๏ธ๐ง
#Python #Programming #DeepCopy #Coding #Tech #Dev
โจ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
Telegram
AI PYTHON ๐
Youโve been invited to add the folder โAI PYTHON ๐โ, which includes 14 chats.
โค6
Regular for-loops are versatile but not always optimal: they add extra interpreter overhead, which is especially noticeable on large data ๐
In such cases, it's better to use standard Python tools, for example itertools โ๏ธ
For example, to get all unique pairs from a list, nested loops are not needed โ just combinations():
Conclusion: instead of manual loops, it's better to use ready-made tools from the standard library โ it's cleaner and more efficient ๐
#Python #Coding #Programming #Developer #Tech #Optimization
โจ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
In such cases, it's better to use standard Python tools, for example itertools โ๏ธ
For example, to get all unique pairs from a list, nested loops are not needed โ just combinations():
from itertools import combinations
def get_unique_pairs(items):
return list(combinations(items, 2))
print(get_unique_pairs(['A', 'B', 'C', 'D']))
# Output:
# [('A', 'B'), ('A', 'C'), ('A', 'D'), ('B', 'C'), ('B', 'D'), ('C', 'D')]
Conclusion: instead of manual loops, it's better to use ready-made tools from the standard library โ it's cleaner and more efficient ๐
#Python #Coding #Programming #Developer #Tech #Optimization
โจ Join Best TG Channels https://t.iss.one/addlist/0f6vfFbEMdAwODBk
โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
โค5๐1
โก๏ธ How Redis counts billions of unique values while barely using memory
There's an algorithm called HyperLogLog. It allows you to roughly estimate how many unique elements have passed through the system, using about 12 KB of memory.
The idea is simple: Redis doesn't store the elements themselves.
It does the following:
- Takes an element
- Calculates a hash from it
- Uses part of the hash as a cell number
- Checks the other part to see how many consecutive zeros it contains
- If the new number is larger than the old one, it updates the cell
Why does this work?
Because a long series of zeros in the hash is rare.
For example:
- 1 consecutive zero - quite common
- 5 consecutive zeros - less common
- 10 consecutive zeros - about a 1 in 1024 chance
- 20 consecutive zeros - a very rare event
If Redis sees a very rare pattern, it means that many different elements have likely passed through it.
Redis uses 16,384 small counters. Each stores the maximum "rarity" it has seen for its group of elements.
Then Redis combines these values mathematically to get an estimate of unique elements.
Not an exact number, but a very close approximation.
The main trick of HyperLogLog:
it can handle millions or even billions of values, but memory hardly increases at all.
That's why Redis can count unique users, IPs, requests, or events without huge tables and lists.
#Redis #HyperLogLog #DataScience #Tech #BigData #MemoryEfficiency
โจ Join Best TG Channels https://t.iss.one/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
There's an algorithm called HyperLogLog. It allows you to roughly estimate how many unique elements have passed through the system, using about 12 KB of memory.
The idea is simple: Redis doesn't store the elements themselves.
It does the following:
- Takes an element
- Calculates a hash from it
- Uses part of the hash as a cell number
- Checks the other part to see how many consecutive zeros it contains
- If the new number is larger than the old one, it updates the cell
Why does this work?
Because a long series of zeros in the hash is rare.
For example:
- 1 consecutive zero - quite common
- 5 consecutive zeros - less common
- 10 consecutive zeros - about a 1 in 1024 chance
- 20 consecutive zeros - a very rare event
If Redis sees a very rare pattern, it means that many different elements have likely passed through it.
Redis uses 16,384 small counters. Each stores the maximum "rarity" it has seen for its group of elements.
Then Redis combines these values mathematically to get an estimate of unique elements.
Not an exact number, but a very close approximation.
The main trick of HyperLogLog:
it can handle millions or even billions of values, but memory hardly increases at all.
That's why Redis can count unique users, IPs, requests, or events without huge tables and lists.
#Redis #HyperLogLog #DataScience #Tech #BigData #MemoryEfficiency
โจ Join Best TG Channels https://t.iss.one/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
A 14-day tutorial where you build a Python code-agent CLI in the style of Claude Code from scratch and simultaneously understand how the Agent Harness actually works. ๐ ๏ธ๐ค
In the end, you don't just call a ready-made agent via the API, but you understand the components that make up a Claude Code-like tool. ๐ง โ๏ธ
https://github.com/bozhouDev/14days-build-claude-code-cli/blob/main/README.en.md
#Python #AI #ClaudeCode #CLI #CodingTutorial #Tech
โจ Join Best TG Channels https://t.iss.one/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
In the end, you don't just call a ready-made agent via the API, but you understand the components that make up a Claude Code-like tool. ๐ง โ๏ธ
https://github.com/bozhouDev/14days-build-claude-code-cli/blob/main/README.en.md
#Python #AI #ClaudeCode #CLI #CodingTutorial #Tech
โจ Join Best TG Channels https://t.iss.one/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
GitHub
14days-build-claude-code-cli/README.en.md at main ยท bozhouDev/14days-build-claude-code-cli
็ฝ้กต็ๆ็จ๏ผ็่ตทๆฅไผ่ๆไธ็น. Contribute to bozhouDev/14days-build-claude-code-cli development by creating an account on GitHub.
โค2๐ฅ1
Python can substitute an empty context manager without conditions inside!
It often happens that a resource needs to be opened via
This usually leads to code duplication or conditions around
`nullcontext(obj)
But note that
๐ฅ
#Python #ContextManager #CodingTips #DevLife #Programming #Tech
โจ Join Best TG Channels https://t.iss.one/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
It often happens that a resource needs to be opened via
with, and sometimes the object is already ready and there's no need to open anything.This usually leads to code duplication or conditions around
with:if need_open:
f = open(...)
else:
f = existing_file
`nullcontext(obj)
behaves like an empty context manager and allows you to maintain a single execution flow.
This is especially useful for APIs, tests, optional resources, dependency injection, and functions that can accept both a path and a ready-made object.
with ctx as resource:
process(resource)
But note that
nullcontext() does not close the passed object โ it simply passes it on further.๐ฅ
nullcontext() helps to unify scenarios with optional context managers and significantly simplifies the architecture of IO code.#Python #ContextManager #CodingTips #DevLife #Programming #Tech
โจ Join Best TG Channels https://t.iss.one/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
Do you know that Python can shift sequences without slicing and creating new lists?
When you need to cyclically shift data, many use slicing:
data = data[-1:] + data[:-1]
But deque.rotate() does this at the level of the data structure and usually works more efficiently for cyclical operations.
q.rotate(1)
A negative value rotates the queue in the other direction.
q.rotate(-2)
This is useful for ring buffers, task schedulers, cyclical queues, and round-robin algorithms.
workers.rotate(-1)
๐ฅ deque.rotate() allows you to implement cyclical data structures without manual index logic and without creating new lists.
#Python #DataStructures #CodingTips #Programming #Deque #Tech
โจ Join Best TG Channels https://t.iss.one/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
When you need to cyclically shift data, many use slicing:
data = data[-1:] + data[:-1]
But deque.rotate() does this at the level of the data structure and usually works more efficiently for cyclical operations.
q.rotate(1)
A negative value rotates the queue in the other direction.
q.rotate(-2)
This is useful for ring buffers, task schedulers, cyclical queues, and round-robin algorithms.
workers.rotate(-1)
๐ฅ deque.rotate() allows you to implement cyclical data structures without manual index logic and without creating new lists.
#Python #DataStructures #CodingTips #Programming #Deque #Tech
โจ Join Best TG Channels https://t.iss.one/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
How to create your own context manager in Python for opening and closing a connection to the SQLite database
The enter() method is used when opening a connection, and the exit() method is used when closing it:
โจ Join Best TG Channels https://t.iss.one/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
#Python #SQLite #ContextManager #Programming #Coding #Tech
The enter() method is used when opening a connection, and the exit() method is used when closing it:
import sqlite3
class DatabaseConnection:
def __init__(self, db_name):
self.db_name = db_name
self.connection = None
def __enter__(self):
self.connection = sqlite3.connect(self.db_name)
return self.connection
def __exit__(self, exc_type, exc_val, exc_tb):
if self.connection:
self.connection.close()
# Usage
with DatabaseConnection("example.db") as conn:
cursor = conn.cursor()
cursor.execute("SELECT * FROM users")
โจ Join Best TG Channels https://t.iss.one/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
#Python #SQLite #ContextManager #Programming #Coding #Tech
โค3
Catch a useful trick for working with division in Python ๐
#Python #Coding #Programming #Tech #Tips #Dev
โจ Join Best TG Channels https://t.iss.one/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
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.iss.one/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
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.iss.one/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
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.iss.one/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.iss.one/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
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.iss.one/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