Code With Python – Telegram
Code With Python
39.3K subscribers
927 photos
30 videos
22 files
789 links
This channel delivers clear, practical content for developers, covering Python, Django, Data Structures, Algorithms, and DSA – perfect for learning, coding, and mastering key programming skills.
Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
This channels is for Programmers, Coders, Software Engineers.

0️⃣ Python
1️⃣ Data Science
2️⃣ Machine Learning
3️⃣ Data Visualization
4️⃣ Artificial Intelligence
5️⃣ Data Analysis
6️⃣ Statistics
7️⃣ Deep Learning
8️⃣ programming Languages

https://news.1rj.ru/str/addlist/8_rRW2scgfRhOTc0

https://news.1rj.ru/str/Codeprogrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
1
augmented coding | AI Coding Glossary

📖 A software development approach combining human expertise with AI-powered coding assistants to enhance productivity while maintaining developer control.

🏷️ #Python
3
Forwarded from Learn Python Hub
This channels is for Programmers, Coders, Software Engineers.

0️⃣ Python
1️⃣ Data Science
2️⃣ Machine Learning
3️⃣ Data Visualization
4️⃣ Artificial Intelligence
5️⃣ Data Analysis
6️⃣ Statistics
7️⃣ Deep Learning
8️⃣ programming Languages

https://news.1rj.ru/str/addlist/8_rRW2scgfRhOTc0

https://news.1rj.ru/str/Codeprogrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
🧠 How to Slow Down Python to a Snail's Pace?

Do you dream of making your noscript run in slow motion? Use these proven methods to turn fast code into annoyingly slow crap.

Don't do this (the obvious and boring way)
import time

for i in range(10):
    time.sleep(1)  # Just wait a second on each iteration
    print(i)


The Problem:
It's too predictable. Any stupid reviewer will immediately notice it and delete it.

✔️ The Right Way (Creative Slowing Down)
import random
import threading
import sys

class GlobalSlowdown:
    def __init__(self):
        self.lock = threading.Lock()
    def heavy_calc(self, x):
        with self.lock:  # Imitate the GIL squared
            return sum(i * 0.000001 for i in range(int(x * 10000)))

def main():
    slowdown = GlobalSlowdown()
    data = list(range(1000))
    # Process each element in a random thread with a delay
    threads = []
    for item in data:
        t = threading.Thread(target=lambda: slowdown.heavy_calc(random.random()))
        t.start()
        threads.append(t)
        if random.choice([True, False]):
            sys.stdout.flush()  # A useless call for show
    for t in threads:
        t.join()  # Wait for everything

if __name__ == '__main__':
    main()


How it works:
We create a bunch of threads for a trivial operation. The global lock ensures that they won't work in parallel, but sequentially, but with the overhead of context switching. The perfect storm of inefficiency.

Let's complicate it: recursion + cache misses:
from functools import lru_cache

@lru_cache(maxsize=2)  # Cache for only 2 elements
def fib(n):
    if n <= 1:
        return n
    # Call it twice with the same arguments to hit the cache misses
    return fib(n-1) + fib(n-2)

# The calculation will take forever
print(fib(50))

The cache is too small to help. The algorithm slows down exponentially, wasting time on constant cache misses.

Pro Tip: Killing the Garbage Collector:
🔵Create cyclic references in huge object graphs

🔵Disable GC: gc.disable()

🔵Use globals() to store everything so the memory never gets freed

Important:
These tricks won't just slow down execution, they'll make the code completely unsupported. Your colleague will curse the day he decided to debug this.

👩‍💻 https://news.1rj.ru/str/DataScience4
Please open Telegram to view this post
VIEW IN TELEGRAM
5
TinyDB: A Lightweight JSON Database for Small Projects

📖 If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be exactly what you need.

🏷️ #basics #databases #python
1
type checking | Python Best Practices

📖 Guidelines and best practices for leveraging type hints and static type checking in your Python code.

🏷️ #Python
Quiz: Python's pathlib Module: Taming the File System

📖 Revisit Python's pathlib module for handling file and folder paths consistently across operating systems. Write modern, object-oriented code.

🏷️ #intermediate #python #stdlib
1
variables | Python Best Practices

📖 Guidelines and best practices for using variables like an expert Python developer.

🏷️ #Python
Quiz: What Exactly Is the Zen of Python?

📖 Learn and test the Zen of Python, its guiding aphorisms, and tips for writing clearer, more readable, and maintainable code.

🏷️ #basics #python
1
What Exactly Is the Zen of Python?

📖 The Zen of Python is a collection of 19 guiding principles for writing good Python code. Learn its history, meaning, and hidden jokes.

🏷️ #basics #python
👨‍💻 Removing the background from any image in a few seconds with Python!

Do you want to automate image processing without Photoshop? 
A noscript project based on the rembg library:

📦 Installation:
pip install rembg


Example code:
from rembg import remove


def remove_background(input_path: str, output_path: str) -> None:
    """Removes the background from the image and saves the result."""
    with open(input_path, 'rb') as input_file:
        with open(output_path, 'wb') as output_file:
            image_bytes: bytes = input_file.read()
            output_bytes: bytes = remove(image_bytes)
            output_file.write(output_bytes)

if __name__ == "__main__":
    remove_background('input.png', 'output.png')


🟢Opens the file;
🟢Removes the background;
🟢Saves the finished image.

5️⃣ GitHub/Instructions

#python #soft #code
Please open Telegram to view this post
VIEW IN TELEGRAM
13
virtual environments | Python Best Practices

📖 Guidelines and best practices for setting up Python virtual environments.

🏷️ #Python
Quiz: Python's list Data Type: A Deep Dive With Examples

📖 Check your Python list skills with quick tasks on indexing, slicing, methods, copies, comprehensions, and pitfalls.

🏷️ #intermediate #data-structures #python
The biggest surprise for our valued audience: we are offering 40 paid courses completely free.

Enroll Here and request
https://adsly.me/l/jwxfnss0yi

We use a spam/flood protection system to ensure that all registered users are real people.
This channels is for Programmers, Coders, Software Engineers.

0️⃣ Python
1️⃣ Data Science
2️⃣ Machine Learning
3️⃣ Data Visualization
4️⃣ Artificial Intelligence
5️⃣ Data Analysis
6️⃣ Statistics
7️⃣ Deep Learning
8️⃣ programming Languages

https://news.1rj.ru/str/addlist/8_rRW2scgfRhOTc0

https://news.1rj.ru/str/Codeprogrammer
Please open Telegram to view this post
VIEW IN TELEGRAM
1
version control (source control) | Python Best Practices

📖 Guidelines and best practices for version-controlling your Python code.

🏷️ #Python
Cheat sheet for Python: covers data structures (list, dict, set), functions and default arguments, comprehensions, classes and inheritance, property and methods, control flow (if/for/while), working with modules, code style (PEP8) and basic patterns
6🔥1
Forwarded from Udemy Coupons
Python Development & Data Science: Variables and Data Types

Python Development, Data Science: Variables and Data Types Course by MTF Institute...

🏷 Category: development
🌍 Language: English (US)
👥 Students: 52,441 students
⭐️ Rating: 4.0/5.0 (892 reviews)
🏃‍♂️ Enrollments Left: 999
Expires In: 2D:11H:19M
💰 Price: $9.59 => FREE
🆔 Coupon: EF144C07A7728DAF0893

⚠️ Please note: A verification layer has been added to prevent bad actors and bots from claiming the courses, so it is important for genuine users to enroll manually to not lose this free opportunity.

💎 By: https://news.1rj.ru/str/DataScienceC
6
Use itertools instead of loops

Although loops are cool, they have limitations, especially in modern programming styles and for certain types of tasks. Understanding these limitations helps to choose the right tool for the task. Each iteration of a loop in Python incurs interpreter overhead, such as type checking and memory management. On large datasets, this can add up significantly.

To circumvent this limitation, Python has a convenient built-in library called itertools. For example, suppose you need to generate all unique pairs from a given list. The order doesn't matter, and no element should form a pair with itself.

To avoid bloated code and reduce the risk of bugs, you can use the itertools library. The function itertools.combinations() directly generates all unique combinations of elements from an iterable without duplicates and without considering order.

Here's how to rewrite the code using combinations from itertools:

from itertools import combinations

def get_unique_pairs_itertools(items):
    return list(combinations(items, 2))

my_list = ['A', 'B', 'C', 'D']
print(get_unique_pairs_itertools(my_list))

Output:
[('A', 'B'), ('A', 'C'), ('A', 'D'), ('B', 'C'), ('B', 'D'), ('C', 'D')]



👉 @datascience4
Please open Telegram to view this post
VIEW IN TELEGRAM
5
Quiz: TinyDB: A Lightweight JSON Database for Small Projects

📖 If you're looking for a JSON document-oriented database that requires no configuration for your Python project, TinyDB could be what you need.

🏷️ #basics #databases #python
security | Python Best Practices

📖 Guidelines and best practices to help prevent security vulnerabilities in your Python code.

🏷️ #Python
2