Python Interview Questions:
Ready to test your Python skills? Letโs get started! ๐ป
1. How to check if a string is a palindrome?
2. How to find the factorial of a number using recursion?
3. How to merge two dictionaries in Python?
4. How to find the intersection of two lists?
5. How to generate a list of even numbers from 1 to 100?
6. How to find the longest word in a sentence?
7. How to count the frequency of elements in a list?
8. How to remove duplicates from a list while maintaining the order?
9. How to reverse a linked list in Python?
10. How to implement a simple binary search algorithm?
Here you can find essential Python Interview Resources๐
https://t.iss.one/DataSimplifier
Like for more resources like this ๐ โฅ๏ธ
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
Ready to test your Python skills? Letโs get started! ๐ป
1. How to check if a string is a palindrome?
def is_palindrome(s):
return s == s[::-1]
print(is_palindrome("madam")) # True
print(is_palindrome("hello")) # False
2. How to find the factorial of a number using recursion?
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
print(factorial(5)) # 120
3. How to merge two dictionaries in Python?
dict1 = {'a': 1, 'b': 2}
dict2 = {'c': 3, 'd': 4}
# Method 1 (Python 3.5+)
merged_dict = {**dict1, **dict2}
# Method 2 (Python 3.9+)
merged_dict = dict1 | dict2
print(merged_dict)
4. How to find the intersection of two lists?
list1 = [1, 2, 3, 4]
list2 = [3, 4, 5, 6]
intersection = list(set(list1) & set(list2))
print(intersection) # [3, 4]
5. How to generate a list of even numbers from 1 to 100?
even_numbers = [i for i in range(1, 101) if i % 2 == 0]
print(even_numbers)
6. How to find the longest word in a sentence?
def longest_word(sentence):
words = sentence.split()
return max(words, key=len)
print(longest_word("Python is a powerful language")) # "powerful"
7. How to count the frequency of elements in a list?
from collections import Counter
my_list = [1, 2, 2, 3, 3, 3, 4]
frequency = Counter(my_list)
print(frequency) # Counter({3: 3, 2: 2, 1: 1, 4: 1})
8. How to remove duplicates from a list while maintaining the order?
def remove_duplicates(lst):
return list(dict.fromkeys(lst))
my_list = [1, 2, 2, 3, 4, 4, 5]
print(remove_duplicates(my_list)) # [1, 2, 3, 4, 5]
9. How to reverse a linked list in Python?
class Node:
def __init__(self, data):
self.data = data
self.next = None
def reverse_linked_list(head):
prev = None
current = head
while current:
next_node = current.next
current.next = prev
prev = current
current = next_node
return prev
# Create linked list: 1 -> 2 -> 3
head = Node(1)
head.next = Node(2)
head.next.next = Node(3)
# Reverse and print the list
reversed_head = reverse_linked_list(head)
while reversed_head:
print(reversed_head.data, end=" -> ")
reversed_head = reversed_head.next
10. How to implement a simple binary search algorithm?
def binary_search(arr, target):
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
return -1
print(binary_search([1, 2, 3, 4, 5, 6, 7], 4)) # 3
Here you can find essential Python Interview Resources๐
https://t.iss.one/DataSimplifier
Like for more resources like this ๐ โฅ๏ธ
Share with credits: https://t.iss.one/sqlspecialist
Hope it helps :)
โค8๐6
Top 10 Python Libraries for Data Science & Machine Learning
1. NumPy: NumPy is a fundamental package for scientific computing in Python. It provides support for large, multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on these arrays.
2. Pandas: Pandas is a powerful data manipulation library that provides data structures like DataFrame and Series, which make it easy to work with structured data. It offers tools for data cleaning, reshaping, merging, and slicing data.
3. Matplotlib: Matplotlib is a plotting library for creating static, interactive, and animated visualizations in Python. It allows you to generate various types of plots, including line plots, bar charts, histograms, scatter plots, and more.
4. Scikit-learn: Scikit-learn is a machine learning library that provides simple and efficient tools for data mining and data analysis. It includes a wide range of algorithms for classification, regression, clustering, dimensionality reduction, and model selection.
5. TensorFlow: TensorFlow is an open-source machine learning framework developed by Google. It enables you to build and train deep learning models using high-level APIs and tools for neural networks, natural language processing, computer vision, and more.
6. Keras: Keras is a high-level neural networks API that runs on top of TensorFlow, Theano, or Microsoft Cognitive Toolkit. It allows you to quickly prototype deep learning models with minimal code and easily experiment with different architectures.
7. Seaborn: Seaborn is a data visualization library based on Matplotlib that provides a high-level interface for creating attractive and informative statistical graphics. It simplifies the process of creating complex visualizations like heatmaps, violin plots, and pair plots.
8. Statsmodels: Statsmodels is a library that focuses on statistical modeling and hypothesis testing in Python. It offers a wide range of statistical models, including linear regression, logistic regression, time series analysis, and more.
9. XGBoost: XGBoost is an optimized gradient boosting library that provides an efficient implementation of the gradient boosting algorithm. It is widely used in machine learning competitions and has become a popular choice for building accurate predictive models.
10. NLTK (Natural Language Toolkit): NLTK is a library for natural language processing (NLP) that provides tools for text processing, tokenization, part-of-speech tagging, named entity recognition, sentiment analysis, and more. It is a valuable resource for working with textual data in data science projects.
Data Science Resources for Beginners
๐๐
https://drive.google.com/drive/folders/1uCShXgmol-fGMqeF2hf9xA5XPKVSxeTo
Share with credits: https://t.iss.one/datasciencefun
ENJOY LEARNING ๐๐
1. NumPy: NumPy is a fundamental package for scientific computing in Python. It provides support for large, multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on these arrays.
2. Pandas: Pandas is a powerful data manipulation library that provides data structures like DataFrame and Series, which make it easy to work with structured data. It offers tools for data cleaning, reshaping, merging, and slicing data.
3. Matplotlib: Matplotlib is a plotting library for creating static, interactive, and animated visualizations in Python. It allows you to generate various types of plots, including line plots, bar charts, histograms, scatter plots, and more.
4. Scikit-learn: Scikit-learn is a machine learning library that provides simple and efficient tools for data mining and data analysis. It includes a wide range of algorithms for classification, regression, clustering, dimensionality reduction, and model selection.
5. TensorFlow: TensorFlow is an open-source machine learning framework developed by Google. It enables you to build and train deep learning models using high-level APIs and tools for neural networks, natural language processing, computer vision, and more.
6. Keras: Keras is a high-level neural networks API that runs on top of TensorFlow, Theano, or Microsoft Cognitive Toolkit. It allows you to quickly prototype deep learning models with minimal code and easily experiment with different architectures.
7. Seaborn: Seaborn is a data visualization library based on Matplotlib that provides a high-level interface for creating attractive and informative statistical graphics. It simplifies the process of creating complex visualizations like heatmaps, violin plots, and pair plots.
8. Statsmodels: Statsmodels is a library that focuses on statistical modeling and hypothesis testing in Python. It offers a wide range of statistical models, including linear regression, logistic regression, time series analysis, and more.
9. XGBoost: XGBoost is an optimized gradient boosting library that provides an efficient implementation of the gradient boosting algorithm. It is widely used in machine learning competitions and has become a popular choice for building accurate predictive models.
10. NLTK (Natural Language Toolkit): NLTK is a library for natural language processing (NLP) that provides tools for text processing, tokenization, part-of-speech tagging, named entity recognition, sentiment analysis, and more. It is a valuable resource for working with textual data in data science projects.
Data Science Resources for Beginners
๐๐
https://drive.google.com/drive/folders/1uCShXgmol-fGMqeF2hf9xA5XPKVSxeTo
Share with credits: https://t.iss.one/datasciencefun
ENJOY LEARNING ๐๐
โค6
๐๐ฆ๐ฉ๐จ๐ซ๐ญ๐ข๐ง๐ ๐๐๐๐๐ฌ๐ฌ๐๐ซ๐ฒ ๐๐ข๐๐ซ๐๐ซ๐ข๐๐ฌ:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
๐๐จ๐๐๐ข๐ง๐ ๐ญ๐ก๐ ๐๐๐ญ๐๐ฌ๐๐ญ:
df = pd.read_csv('your_dataset.csv')
๐๐ง๐ข๐ญ๐ข๐๐ฅ ๐๐๐ญ๐ ๐๐ง๐ฌ๐ฉ๐๐๐ญ๐ข๐จ๐ง:
1- View the first few rows:
df.head()
2- Summary of the dataset:
df.info()
3- Statistical summary:
df.describe()
๐๐๐ง๐๐ฅ๐ข๐ง๐ ๐๐ข๐ฌ๐ฌ๐ข๐ง๐ ๐๐๐ฅ๐ฎ๐๐ฌ:
1- Identify missing values:
df.isnull().sum()
2- Visualize missing values:
sns.heatmap(df.isnull(), cbar=False, cmap='viridis')
plt.show()
๐๐๐ญ๐ ๐๐ข๐ฌ๐ฎ๐๐ฅ๐ข๐ณ๐๐ญ๐ข๐จ๐ง:
1- Histograms:
df.hist(bins=30, figsize=(20, 15))
plt.show()
2 - Box plots:
plt.figure(figsize=(10, 6))
sns.boxplot(data=df)
plt.xticks(rotation=90)
plt.show()
3- Pair plots:
sns.pairplot(df)
plt.show()
4- Correlation matrix and heatmap:
correlation_matrix = df.corr()
plt.figure(figsize=(12, 8))
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm')
plt.show()
๐๐๐ญ๐๐ ๐จ๐ซ๐ข๐๐๐ฅ ๐๐๐ญ๐ ๐๐ง๐๐ฅ๐ฒ๐ฌ๐ข๐ฌ:
Count plots for categorical features:
plt.figure(figsize=(10, 6))
sns.countplot(x='categorical_column', data=df)
plt.show()
Python Interview Q&A: https://whatsapp.com/channel/0029Vau5fZECsU9HJFLacm2a
Like for more โค๏ธ
ENJOY LEARNING ๐๐
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
๐๐จ๐๐๐ข๐ง๐ ๐ญ๐ก๐ ๐๐๐ญ๐๐ฌ๐๐ญ:
df = pd.read_csv('your_dataset.csv')
๐๐ง๐ข๐ญ๐ข๐๐ฅ ๐๐๐ญ๐ ๐๐ง๐ฌ๐ฉ๐๐๐ญ๐ข๐จ๐ง:
1- View the first few rows:
df.head()
2- Summary of the dataset:
df.info()
3- Statistical summary:
df.describe()
๐๐๐ง๐๐ฅ๐ข๐ง๐ ๐๐ข๐ฌ๐ฌ๐ข๐ง๐ ๐๐๐ฅ๐ฎ๐๐ฌ:
1- Identify missing values:
df.isnull().sum()
2- Visualize missing values:
sns.heatmap(df.isnull(), cbar=False, cmap='viridis')
plt.show()
๐๐๐ญ๐ ๐๐ข๐ฌ๐ฎ๐๐ฅ๐ข๐ณ๐๐ญ๐ข๐จ๐ง:
1- Histograms:
df.hist(bins=30, figsize=(20, 15))
plt.show()
2 - Box plots:
plt.figure(figsize=(10, 6))
sns.boxplot(data=df)
plt.xticks(rotation=90)
plt.show()
3- Pair plots:
sns.pairplot(df)
plt.show()
4- Correlation matrix and heatmap:
correlation_matrix = df.corr()
plt.figure(figsize=(12, 8))
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm')
plt.show()
๐๐๐ญ๐๐ ๐จ๐ซ๐ข๐๐๐ฅ ๐๐๐ญ๐ ๐๐ง๐๐ฅ๐ฒ๐ฌ๐ข๐ฌ:
Count plots for categorical features:
plt.figure(figsize=(10, 6))
sns.countplot(x='categorical_column', data=df)
plt.show()
Python Interview Q&A: https://whatsapp.com/channel/0029Vau5fZECsU9HJFLacm2a
Like for more โค๏ธ
ENJOY LEARNING ๐๐
โค8
๐ ๐๐ฒ๐ฐ๐ผ๐บ๐ฒ ๐ฎ๐ป ๐๐ด๐ฒ๐ป๐๐ถ๐ฐ ๐๐ ๐๐ฒ๐๐ฒ๐น๐ผ๐ฝ๐ฒ๐ฟ โ ๐๐ฟ๐ฒ๐ฒ ๐๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป ๐ฃ๐ฟ๐ผ๐ด๐ฟ๐ฎ๐บ
Master the hottest skill in tech: building intelligent AI systems that think and act independently.
Join Ready Tensorโs free, hands-on program to create three portfolio-grade projects: RAG systems โ Multi-agent workflows โ Production deployment.
๐๐ฎ๐ฟ๐ป ๐ฝ๐ฟ๐ผ๐ณ๐ฒ๐๐๐ถ๐ผ๐ป๐ฎ๐น ๐ฐ๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป and ๐ด๐ฒ๐ ๐ป๐ผ๐๐ถ๐ฐ๐ฒ๐ฑ ๐ฏ๐ ๐๐ผ๐ฝ ๐๐ ๐ฒ๐บ๐ฝ๐น๐ผ๐๐ฒ๐ฟ๐.
๐๐ฟ๐ฒ๐ฒ. ๐ฆ๐ฒ๐น๐ณ-๐ฝ๐ฎ๐ฐ๐ฒ๐ฑ. ๐๐ฎ๐ฟ๐ฒ๐ฒ๐ฟ-๐ฐ๐ต๐ฎ๐ป๐ด๐ถ๐ป๐ด.
๐ Join today: https://go.readytensor.ai/cert-597-agentic-ai-certification
Double Tap โค๏ธ for more free courses
Master the hottest skill in tech: building intelligent AI systems that think and act independently.
Join Ready Tensorโs free, hands-on program to create three portfolio-grade projects: RAG systems โ Multi-agent workflows โ Production deployment.
๐๐ฎ๐ฟ๐ป ๐ฝ๐ฟ๐ผ๐ณ๐ฒ๐๐๐ถ๐ผ๐ป๐ฎ๐น ๐ฐ๐ฒ๐ฟ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป and ๐ด๐ฒ๐ ๐ป๐ผ๐๐ถ๐ฐ๐ฒ๐ฑ ๐ฏ๐ ๐๐ผ๐ฝ ๐๐ ๐ฒ๐บ๐ฝ๐น๐ผ๐๐ฒ๐ฟ๐.
๐๐ฟ๐ฒ๐ฒ. ๐ฆ๐ฒ๐น๐ณ-๐ฝ๐ฎ๐ฐ๐ฒ๐ฑ. ๐๐ฎ๐ฟ๐ฒ๐ฒ๐ฟ-๐ฐ๐ต๐ฎ๐ป๐ด๐ถ๐ป๐ด.
๐ Join today: https://go.readytensor.ai/cert-597-agentic-ai-certification
Double Tap โค๏ธ for more free courses
โค5