super() is linear. Your brain is not.You have class A, B, C. Multiple inheritance. You call
super().method() inside B. Which method runs? Not necessarily the parent of B. It depends on the Method Resolution Order of the instance.Most developers learn MRO once, forget it, then get confused when
super() jumps sideways instead of up.Take this:
class A:
def f(self): print("A")
class B(A):
def f(self): print("B"); super().f()
class C(A):
def f(self): print("C"); super().f()
class D(B, C):
def f(self): print("D"); super().f()
D().f() prints D, B, C, A. Not B then A. Because super() in B calls next in MRO which is C, not A.This is not a bug. It's cooperative multiple inheritance. It allows mixins and dependency injection. But if you don't understand it, you will spend hours wondering why
super().f() skipped a generation.✔️ The rule:
super() follows the MRO, not the parent hierarchy. Print ClassName.__mro__ before you debug.❤2
Forwarded from Programming Quiz Channel
What is the main advantage of using a Python generator instead of returning a list?
Anonymous Quiz
20%
Better syntax highlighting
11%
Stronger typing
57%
Lower memory consumption
12%
Faster internet access
❤3
🚀 Essential Python snippets to explore data:
1. .head() - Review top rows
2. .tail() - Review bottom rows
3. .info() - Summary of DataFrame
4. .shape - Shape of DataFrame
5. .describe() - Descriptive stats
6. .isnull().sum() - Check missing values
7. .dtypes - Data types of columns
8. .unique() - Unique values in a column
9. .nunique() - Count unique values
10. .value_counts() - Value counts in a column
11. .corr() - Correlation matrix
1. .head() - Review top rows
2. .tail() - Review bottom rows
3. .info() - Summary of DataFrame
4. .shape - Shape of DataFrame
5. .describe() - Descriptive stats
6. .isnull().sum() - Check missing values
7. .dtypes - Data types of columns
8. .unique() - Unique values in a column
9. .nunique() - Count unique values
10. .value_counts() - Value counts in a column
11. .corr() - Correlation matrix
❤6🔥1
Forwarded from Cool GitHub repositories
mypy
Mypy is a static type checker for Python.
Python is a dynamic language, so usually you'll only see errors in your code when you attempt to run it. Mypy is a static checker, so it finds bugs in your programs without even running them.
Creator: python
Stars ⭐️: 20,507
Forked by: 3,225
Github Repo:
https://github.com/python/mypy
➖➖➖➖➖➖➖➖➖➖➖➖➖➖
Join @github_repositories_bds for more cool repositories. This channel belongs to @bigdataspecialist group
Mypy is a static type checker for Python.
Python is a dynamic language, so usually you'll only see errors in your code when you attempt to run it. Mypy is a static checker, so it finds bugs in your programs without even running them.
Creator: python
Stars ⭐️: 20,507
Forked by: 3,225
Github Repo:
https://github.com/python/mypy
➖➖➖➖➖➖➖➖➖➖➖➖➖➖
Join @github_repositories_bds for more cool repositories. This channel belongs to @bigdataspecialist group
GitHub
GitHub - python/mypy: Optional static typing for Python
Optional static typing for Python. Contribute to python/mypy development by creating an account on GitHub.
❤3
Forwarded from Free Programming Books
Python Machine Learning Projects.pdf
2.1 MB
📘Python Machine Learning Projects
✍️ Authors: Lisa Tagliaferri, Michelle Morales, Ellie Birkbeck, Alvin Wan
🗓 Year: 2019
📄 Pages: 135
🧠 This book will set you up with a Python programming environment if you don't have one already, then provide you with a conceptual understanding of machine learning in the chapter "An Introduction to Machine Learning." What follows next are three Python machine learning projects. They will help you create a machine learning classifier, build a neural network to recognize handwritten digits, and give you a background in deep reinforcement learning through building a bot for Atari.
#Python #MachineLearning
────────────────────
👉 @free_programming_books_bds 👈
✍️ Authors: Lisa Tagliaferri, Michelle Morales, Ellie Birkbeck, Alvin Wan
🗓 Year: 2019
📄 Pages: 135
🧠 This book will set you up with a Python programming environment if you don't have one already, then provide you with a conceptual understanding of machine learning in the chapter "An Introduction to Machine Learning." What follows next are three Python machine learning projects. They will help you create a machine learning classifier, build a neural network to recognize handwritten digits, and give you a background in deep reinforcement learning through building a bot for Atari.
#Python #MachineLearning
────────────────────
👉 @free_programming_books_bds 👈
❤3👍1
📊 Essential Python Libraries to build your career in Data Science
1. NumPy:
- Efficient numerical operations and array manipulation.
2. Pandas:
- Data manipulation and analysis with powerful data structures (DataFrame, Series).
3. Matplotlib:
- 2D plotting library for creating visualizations.
4. Seaborn:
- Statistical data visualization built on top of Matplotlib.
5. Scikit-learn:
- Machine learning toolkit for classification, regression, clustering, etc.
6. TensorFlow:
- Open-source machine learning framework for building and deploying ML models.
7. PyTorch:
- Deep learning library, particularly popular for neural network research.
8. SciPy:
- Library for scientific and technical computing.
9. Statsmodels:
- Statistical modeling and econometrics in Python.
10. NLTK (Natural Language Toolkit):
- Tools for working with human language data (text).
11. Gensim:
- Topic modeling and document similarity analysis.
12. Keras:
- High-level neural networks API, running on top of TensorFlow.
13. Plotly:
- Interactive graphing library for making interactive plots.
14. Beautiful Soup:
- Web scraping library for pulling data out of HTML and XML files.
15. OpenCV:
- Library for computer vision tasks.
As a beginner, you can start with Pandas and NumPy for data manipulation and analysis. For data visualization, Matplotlib and Seaborn are great starting points. As you progress, you can explore machine learning with Scikit-learn, TensorFlow, and PyTorch.
1. NumPy:
- Efficient numerical operations and array manipulation.
2. Pandas:
- Data manipulation and analysis with powerful data structures (DataFrame, Series).
3. Matplotlib:
- 2D plotting library for creating visualizations.
4. Seaborn:
- Statistical data visualization built on top of Matplotlib.
5. Scikit-learn:
- Machine learning toolkit for classification, regression, clustering, etc.
6. TensorFlow:
- Open-source machine learning framework for building and deploying ML models.
7. PyTorch:
- Deep learning library, particularly popular for neural network research.
8. SciPy:
- Library for scientific and technical computing.
9. Statsmodels:
- Statistical modeling and econometrics in Python.
10. NLTK (Natural Language Toolkit):
- Tools for working with human language data (text).
11. Gensim:
- Topic modeling and document similarity analysis.
12. Keras:
- High-level neural networks API, running on top of TensorFlow.
13. Plotly:
- Interactive graphing library for making interactive plots.
14. Beautiful Soup:
- Web scraping library for pulling data out of HTML and XML files.
15. OpenCV:
- Library for computer vision tasks.
As a beginner, you can start with Pandas and NumPy for data manipulation and analysis. For data visualization, Matplotlib and Seaborn are great starting points. As you progress, you can explore machine learning with Scikit-learn, TensorFlow, and PyTorch.
❤5
Forwarded from Free Programming Books
📘Python Data Science Handbook
✍️ Author: Jake VanderPlas
🔗 Read Online
#Python #DataScience
────────────────────
👉 @free_programming_books_bds 👈
✍️ Author: Jake VanderPlas
🔗 Read Online
#Python #DataScience
────────────────────
👉 @free_programming_books_bds 👈
🔥 12 Python Tricks That Make Your Code Cleaner
Here are some Python tricks every developer should know.
1. Swap variables without a temporary variable.
2. Reverse a list.
3. Chain comparisons.
4. Multiple assignment.
5. Unpack lists.
6. Use underscores for ignored values.
7. Format strings with f-strings.
8. Merge dictionaries.
9. Remove duplicates.
10. Check membership using sets.
11. Readable large numbers.
12. Use with for files.
Here are some Python tricks every developer should know.
1. Swap variables without a temporary variable.
a, b = b, a
2. Reverse a list.
nums[::-1]
3. Chain comparisons.
10 < age < 30
4. Multiple assignment.
x = y = z = 0
5. Unpack lists.
first, *middle, last = nums
6. Use underscores for ignored values.
name, _, age = data
7. Format strings with f-strings.
print(f"Hello {name}")8. Merge dictionaries.
new = dict1 | dict2
9. Remove duplicates.
unique = list(set(nums))
10. Check membership using sets.
if color in {"red", "green", "blue"}:11. Readable large numbers.
salary = 1_000_000
12. Use with for files.
with open("data.txt") as f:
data = f.read()❤2
✅ Python Scenario-Based Interview Question – List Comprehension 🐍
Scenario:
You are given a list of numbers:
Question:
Write Python code to create a new list that contains:
1. Only the even numbers from the original list.
2. Each even number multiplied by 2.
Expected Output:
Answer:
Explanation:
⦁ The list comprehension iterates over each
⦁ The
⦁ For those,
Scenario:
You are given a list of numbers:
numbers = [1, 2, 3, 4, 5, 6]
Question:
Write Python code to create a new list that contains:
1. Only the even numbers from the original list.
2. Each even number multiplied by 2.
Expected Output:
Answer:
even_doubled = [num * 2 for num in numbers if num % 2 == 0]
print(even_doubled)
Explanation:
⦁ The list comprehension iterates over each
num in numbers.⦁ The
if num % 2 == 0 condition filters to only even numbers (remainder 0 when divided by 2).⦁ For those,
num * 2 doubles them, building the new list concisely.❤4
❌ Five mistakes almost every Python developer makes once
1️⃣ Giving a function a default value that's a list or dictionary. This one is sneaky because it works in your first few tests and then quietly breaks the moment the function gets called more than once because that default gets created a single time, not fresh on every call, and it silently keeps growing in the background.
2️⃣ Creating a bunch of small functions inside a loop that each reference the loop variable
People expect each one to remember its "own" value from when it was created. They don't. They all end up referencing whatever the loop variable became by the time the loop finished, which is almost never what you wanted.
3️⃣ Comparing decimal numbers with a plain equals sign
Computers don't store decimal math with perfect precision, so two numbers that should obviously be equal sometimes aren't, according to the computer. There's a proper "close enough" comparison built for exactly this.
4️⃣ Confusing a quick copy with a real copy
A fast, shallow copy of something with nested lists or dictionaries inside still shares those inner pieces with the original change one, and you accidentally change both. A true independent copy needs a different approach entirely.
5️⃣ Catching every possible error with one generic catch-all
It feels protective in the moment, but it also hides real bugs behind the same wall as the error you actually expected, and you lose the ability to tell them apart.
None of these mean you're bad at this. Almost everyone hits each one exactly once, and then never forgets it.
1️⃣ Giving a function a default value that's a list or dictionary. This one is sneaky because it works in your first few tests and then quietly breaks the moment the function gets called more than once because that default gets created a single time, not fresh on every call, and it silently keeps growing in the background.
2️⃣ Creating a bunch of small functions inside a loop that each reference the loop variable
People expect each one to remember its "own" value from when it was created. They don't. They all end up referencing whatever the loop variable became by the time the loop finished, which is almost never what you wanted.
3️⃣ Comparing decimal numbers with a plain equals sign
Computers don't store decimal math with perfect precision, so two numbers that should obviously be equal sometimes aren't, according to the computer. There's a proper "close enough" comparison built for exactly this.
4️⃣ Confusing a quick copy with a real copy
A fast, shallow copy of something with nested lists or dictionaries inside still shares those inner pieces with the original change one, and you accidentally change both. A true independent copy needs a different approach entirely.
5️⃣ Catching every possible error with one generic catch-all
It feels protective in the moment, but it also hides real bugs behind the same wall as the error you actually expected, and you lose the ability to tell them apart.
None of these mean you're bad at this. Almost everyone hits each one exactly once, and then never forgets it.
❤4
📂 Understanding Python File Modes
When opening a file, the mode determines what you're allowed to do.
Mode Meaning
👉 Using the wrong mode is one of the easiest ways to accidentally erase a file.
When opening a file, the mode determines what you're allowed to do.
Mode Meaning
r 👉 Read onlyw 👉 Write (overwrites existing file)a 👉 Append to the endx 👉 Create a new filerb 👉 Read binary fileswb 👉 Write binary filesr+ 👉 Read and write👉 Using the wrong mode is one of the easiest ways to accidentally erase a file.
🔥4
Forwarded from Programming Quiz Channel
Which statement about Python tuples is true?
Anonymous Quiz
25%
They cannot contain duplicate values
4%
They can only store numbers
7%
They are always sorted automatically
63%
They are immutable after creation
❤2
📦 The Difference Between a Package and a Module
These terms get mixed up a lot.
📗A module is a single Python file.
📚A package is a folder containing multiple modules.
Think of it like this:
📖 Module = One book
📚 Package = An entire bookshelf
These terms get mixed up a lot.
📗A module is a single Python file.
math.py
📚A package is a folder containing multiple modules.
utils/
helpers.py
parser.py
formatter.py
Think of it like this:
📖 Module = One book
📚 Package = An entire bookshelf
👍2