Advanced Python Made Easy — Part 1
Use these hacks and techniques…

Python, created by Guido van Rossum in 1991, is an interpreted, high level-general purpose programming language. Most of us, working in software engineering field must have used Python in our work life. In this post, I’m going to cover the advanced python constructs and how you can efficiently use them to improve your code readability and performance. This is the part 1 and to be followed by Part 2 (coming soon).
Projects Videos —
All the projects, data structures, SQL, algorithms, system design, Data Science and ML , Data Analytics, Data Engineering, , Implemented Data Science and ML projects, Implemented Data Engineering Projects, Implemented Deep Learning Projects, Implemented Machine Learning Ops Projects, Implemented Time Series Analysis and Forecasting Projects, Implemented Applied Machine Learning Projects, Implemented Tensorflow and Keras Projects, Implemented PyTorch Projects, Implemented Scikit Learn Projects, Implemented Big Data Projects, Implemented Cloud Machine Learning Projects, Implemented Neural Networks Projects, Implemented OpenCV Projects,Complete ML Research Papers Summarized, Implemented Data Analytics projects, Implemented Data Visualization Projects, Implemented Data Mining Projects, Implemented Natural Leaning Processing Projects, MLOps and Deep Learning, Applied Machine Learning with Projects Series, PyTorch with Projects Series, Tensorflow and Keras with Projects Series, Scikit Learn Series with Projects, Time Series Analysis and Forecasting with Projects Series, ML System Design Case Studies Series videos will be published on our youtube channel ( just launched).
Subscribe today!
1. Comprehensions
You must have heard about list comprehensions (Python 2.0). Comprehensions in Python are the constructs that allows sequence built from other sequences and while the list comprehensions are quite popular/frequently used, Python 3.0 introduced Dictionary and set comprehensions.
#Example Codelist_one=[5,10,15, 20]
new_list=[]
for x in list_one:
new_list.append(x**3)
print(new_list)Output —
[125, 1000, 3375, 8000]With list comprehension —
list_two=[5,10,15,20]
new_list=[x**3 for x in list_two]
print(new_list)Output —
[125, 1000, 3375, 8000]With condition —
#With conditionlist_three=[13,20,25,45]
new_list=[x**3 for x in list_three if x%2==0]
print(new_list)Output —
[8000]Dictionary Comprehension
dict_one=[10,20,30,40]
new_dict={x: x**2 for x in dict_one if x%2==0}
print(new_dict)Output —
{10: 100, 20: 400, 30: 900, 40: 1600}Some of the other best Series —
Data Science and Machine Learning Research ( papers) Simplified **
100 days : Your Data Science and Machine Learning Degree Series with projects
Complete Data Visualization and Pre-processing Series with projects
Exceptional Github Repos — Part 1
Exceptional Github Repos — Part 2
Tech Newsletter —
If you are interested, you can join my newsletter through which I send tech interview tips, techniques, patterns, hacks — Software Development, ML, Data Science, Startups and Technology projects to more than 30K readers. You can subscribe to Tech Brew :
Github —
2. Default Dict
Default Dict, a part of high performance container datatypes, is a sub class of dict that returns a dictionary object. It never raises a key error and is initialized with a default factory function.
from collections import defaultdicttuition_balance= defaultdict(lambda:200)tuition_deposits = {'Naina' : 100, 'Steve' : 300, 'Benedict' : 200}for name,deposits in tuition_deposits.items():
tuition_balance[name]+=deposits
print(dict(tuition_balance))Output —
{'Naina': 300, 'Steve': 500, 'Benedict': 400}3. NamedTuple
NamedTuples are light weight, memory efficient object types which belongs to collections module. These are dict like constructs where you can access the attribute values by index, key name or getattr() function.
from typing import NamedTuple
class Account(NamedTuple):
name:str
value: float
Account(name='Naina',value=100)Output —
Account(name='Naina', value=100.1)from collections import defaultdict
tuition_balances= defaultdict(lambda:200)tuition_deposits = [Account(name='Naina', value=100),
Account(name='Steve', value= 300),
Account(name='Benedict',value=200)]for deposit in tuition_deposits:
tuition_balances[deposit.name]+=deposit.value
print(dict(tuition_balances))Output —
{'Naina': 300, 'Steve': 500, 'Benedict': 400}4. Type Hinting
If you are working with complicated data structures, then type hints are very helpful to sort out the complexity and to make your code more readable (especially when you want to refer the code later).
def calc(x:set, y:set) ->set:
var_one = x + y
var_two = x | y
var_three = x & y
return var_three
a: set = {5,6,20,30,10,4,22}
b: set = {20,30,45,6,7,3,22}
result : set=calc(a,b)
print(result)Output —
{6, 20, 22, 30}Here are some advanced techniques in Python for data scientists:
- Pandas: Pandas is a powerful library for data analysis in Python. Data scientists can use it to clean, manipulate, and analyze large datasets with ease.
- Numpy: Numpy is a library for numerical computing in Python. It provides advanced functionality for operations on arrays and matrices, making it an essential tool for data scientists.
- Matplotlib and Seaborn: Matplotlib and Seaborn are libraries for data visualization in Python. They provide a variety of options for creating meaningful and insightful visualizations to help data scientists understand and communicate their findings.
- Scikit-learn: Scikit-learn is a library for machine learning in Python. It provides a wide range of algorithms for tasks such as regression, classification, clustering, and more.
- TensorFlow and PyTorch: TensorFlow and PyTorch are deep learning libraries in Python. They provide the tools and resources necessary for building and training neural networks, making them essential for data scientists who work with large and complex datasets.
- Multithreading and Multiprocessing: Multithreading and multiprocessing are techniques for parallel processing in Python. They allow data scientists to take advantage of multiple cores and processors, making their computations faster and more efficient.
- Function Decorators: Function decorators are a powerful tool for modifying the behavior of functions in Python. Data scientists can use them to add custom functionality, make code more readable, and enforce coding standards.
- Context Managers: Context managers are a way to manage resources in Python, such as opening and closing files, acquiring and releasing locks, and more. Data scientists can use them to simplify their code and improve the reliability and performance of their programs.
- Generators: Generators are a way to generate sequences of values in Python. Data scientists can use them to process large datasets in a memory-efficient manner, as they only generate one value at a time.
- Metaclasses: Metaclasses are a way to modify the behavior of classes in Python. Data scientists can use them to create custom classes, enforce coding standards, and simplify their code.
All the Complete System Design Series Parts —
6. Networking, How Browsers work, Content Network Delivery ( CDN)
Github —
Thanks for Reading. Keep coding .
(Part 2 coming soon)






