Data Science & Machine Learning
76.9K subscribers
850 photos
68 files
762 links
Join this channel to learn data science, artificial intelligence and machine learning with funny quizzes, interesting projects and amazing resources for free

For collaborations: @love_data
Download Telegram
๐Ÿš€ Data Science Roadmap 2026

๐Ÿ“˜ Phase 1: Programming Fundamentals

๐Ÿ Topic 6: Python Functions
 
So far, you've learned variables, operators, input/output, conditional statements, and loops. As your programs grow larger, writing the same code repeatedly becomes inefficient. That's where functions come in. 

A function is a reusable block of code that performs a specific task. Functions make your code cleaner, easier to maintain, and reusable. 

Functions are heavily used in Data Science, Machine Learning, and AI because they allow you to organize complex workflows into smaller, manageable pieces.

๐Ÿ”น 1. What is a Function? 
A function is a named block of code that executes only when it is called. 

Instead of writing the same logic multiple times, you write it once inside a function and reuse it whenever needed. 

Example
def greet():
    print("Welcome to Data Science!")

greet()

Output 
Welcome to Data Science!

๐Ÿ”น 2. Why Do We Use Functions? 

Functions help you: 
โœ… Avoid writing duplicate code 
โœ… Improve code readability 
โœ… Make debugging easier 
โœ… Reuse code in multiple places 
โœ… Build modular applications 

๐Ÿ”น 3. Defining a Function 

Syntax
def function_name():
    # Function body

Example:
def welcome():
    print("Hello, World!")

welcome()

๐Ÿ”น 4. Function Parameters 
Parameters allow you to pass information into a function.
def greet(name):
    print("Hello", name)

greet("Deepak")

Output 
Hello Deepak 

Here, "name" is called a parameter.

๐Ÿ”น 5. Function Arguments 
When calling a function, the values you pass are called arguments.
def square(number):
    print(number * number)

square(5)

Output 
25 

Here: 
โ€ข "number" โ†’ Parameter
โ€ข "5" โ†’ Argument

๐Ÿ”น 6. Returning Values 
A function can return a value using the return keyword.
def add(a, b):
    return a + b

result = add(10, 20)
print(result)

Output 
30 

Using return allows the function's result to be stored or used later.

๐Ÿ”น 7. Default Parameters 
You can assign default values to parameters.
def greet(name="Guest"):
    print("Hello", name)

greet()
greet("Rahul")

Output
Hello Guest
Hello Rahul

๐Ÿ”น 8. Multiple Return Values 
A function can return more than one value.
def calculate(a, b):
    return a + b, a * b

sum_value, product = calculate(4, 5)
print(sum_value)
print(product)

Output
9
20

๐Ÿ”น 9. Scope of Variables 
Variables created inside a function are called local variables.
def demo():
    message = "Inside Function"
    print(message)

demo()

Trying to access
message

outside the function will produce an error because it exists only inside the function.

๐Ÿ”น 10. Built-in Functions 
Python provides many ready-to-use functions. 

Examples:
numbers = [5, 2, 8, 1]
print(len(numbers))
print(max(numbers))
print(min(numbers))
print(sum(numbers))

Output
4
8
1
16

๐Ÿ”น 11. Real-World Data Science Example 
Calculate the average marks of students.
def average(marks):
    return sum(marks) / len(marks)

scores = [80, 75, 92, 88]
print(average(scores))

Output 
83.75 

Functions like this are commonly used while cleaning data, calculating statistics, and building machine learning pipelines.

๐Ÿ”น 12. Common Mistakes 
โŒ Forgetting to Call the Function
def greet():
    print("Hello")

# Nothing happens because the function isn't called.

Correct:
greet()

โŒ Forgetting to Return a Value
def add(a, b):
    a + b

# Correct:
def add(a, b):
    return a + b

๐ŸŽฏ Practice Questions 
1. Write a function to add two numbers.
2. Create a function to calculate the square of a number.
3. Write a function that checks whether a number is even or odd.
4. Create a function to calculate the average of a list.
5. Write a function that returns the largest of three numbers.

Double Tap โค๏ธ For Part-7
โค14
๐Ÿ“ˆ ๐——๐—ฎ๐˜๐—ฎ ๐—”๐—ป๐—ฎ๐—น๐˜†๐˜๐—ถ๐—ฐ๐˜€ ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐Ÿ˜

Data Analytics is one of the most in-demand skills in todayโ€™s job market ๐Ÿ’ป

โœ… Beginner Friendly
โœ… Industry-Relevant Curriculum
โœ… Certification Included
โœ… 100% Online

๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:- 

https://pdlink.in/4wh2ugB

๐ŸŽฏ Donโ€™t miss this opportunity to build high-demand skills!
โค1
Which keyword is used to define a function in Python?
Anonymous Quiz
8%
A) function
84%
B) def
7%
C) func
1%
D) define
โค1
Which keyword is used to return a value from a function?
Anonymous Quiz
3%
A) break
12%
B) print
83%
C) return
2%
D) pass
โค1
Which of the following is a built-in Python function?
Anonymous Quiz
15%
A) calculate()
15%
B) average()
64%
C) sum()
7%
D) multiply()
โค2
What will be the output of the following code?
def multiply(a, b):
return a * b print(multiply(4, 5))
Anonymous Quiz
7%
9
93%
20
โค1๐Ÿฅฐ1
What will be the output of the following code?

def greet(): print("Hello") greet()
Anonymous Quiz
91%
Hello
9%
greet
โค3
๐Ÿš€ ๐—”๐—œ & ๐— ๐—ฎ๐—ฐ๐—ต๐—ถ๐—ป๐—ฒ ๐—Ÿ๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ฒ๐—ฟ๐˜๐—ถ๐—ณ๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐Ÿ”ฅ

Learn the most in-demand AI skills from scratch and strengthen your profile with industry-recognized certificates! ๐ŸŽ“

โœ… Beginner-Friendly Courses
โœ… Learn Online at Your Own Pace
โœ… 100% FREE of cost

Perfect for Students, Freshers & Working Professionals looking to build a career in AI/ML. ๐Ÿ’ผ

๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:- 

https://pdlink.in/4phANS2

๐Ÿ“ข Share this with your friends who want to start their AI career!
โค1
๐Ÿš€ Data Science Roadmap 2026

๐Ÿ“˜ Phase 1: Programming Fundamentals

๐Ÿ Topic 7: Python Data Structures (Lists, Tuples, Sets & Dictionaries)

Welcome back! ๐Ÿ‘‹

So far, you've learned variables, operators, input/output, conditional statements, loops, and functions. Now it's time to learn one of the most important topics in Pythonโ€” Data Structures.

Data structures help us store, organize, and manage data efficiently. In Data Science, almost every dataset you work with will be stored or manipulated using these structures.

Python provides four built-in data structures:

โ€ข List

โ€ข Tuple

โ€ข Set

โ€ข Dictionary

Let's understand each one in detail.

๐Ÿ”น 1. List

A List is an ordered, mutable collection that allows duplicate values.

Creating a List

fruits = ["Apple", "Banana", "Mango"]
print(fruits)


Output

['Apple', 'Banana', 'Mango']


Accessing Elements

print(fruits[0])
print(fruits[2])


Output

Apple
Mango


Modifying a List

fruits[1] = "Orange"
print(fruits)


Output

['Apple', 'Orange', 'Mango']


Adding Elements

fruits.append("Grapes")
print(fruits)


Removing Elements

fruits.remove("Orange")
print(fruits)


๐Ÿ”น 2. Tuple

A Tuple is an ordered collection that cannot be modified after creation (immutable).

Creating a Tuple

colors = ("Red", "Green", "Blue")
print(colors)


Accessing Elements

print(colors[1])


Output

Green


Why Use Tuples?

Use tuples when your data should never change.

Examples:

โ€ข Months of the year

โ€ข Days of the week

โ€ข Fixed coordinates

๐Ÿ”น 3. Set

A Set is an unordered collection of unique elements.

Duplicate values are automatically removed.

Creating a Set

numbers = {1, 2, 2, 3, 4, 4, 5}
print(numbers)


Output

{1, 2, 3, 4, 5}


Adding Elements

numbers.add(6)


Removing Elements

numbers.remove(3)


Common Uses

โ€ข Remove duplicates

โ€ข Membership testing

โ€ข Mathematical set operations

๐Ÿ”น 4. Dictionary โญ

A Dictionary stores data as key-value pairs.

It is one of the most frequently used data structures in Data Science.

Creating a Dictionary

student = {
"name": "Deepak",
"age": 24,
"course": "Data Science"
}
print(student)


Accessing Values

print(student["name"])


Output

Deepak


Adding a New Key

student["city"] = "Mumbai"


Updating a Value

student["age"] = 25


Removing a Key

del student["course"]


๐Ÿ”น 5. Comparison of Data Structures

Feature | List | Tuple | Set | Dictionary

Ordered | โœ… | โœ… | โŒ | โœ…

Mutable | โœ… | โŒ | โœ… | โœ…

Duplicates Allowed | โœ… | โœ… | โŒ | Keys โŒ

Indexed | โœ… | โœ… | โŒ | By Key

๐Ÿ”น 6. Common List Methods

numbers = [10, 20, 30]
numbers.append(40)
numbers.insert(1, 15)
numbers.remove(20)
numbers.sort()
print(numbers)


๐Ÿ”น 7. Common Dictionary Methods
โค3
student = {
"name": "Rahul",
"age": 23
}
print(student.keys())
print(student.values())
print(student.items())


๐Ÿ”น 8. Real-World Data Science Example

Suppose you have student information.

students = [
{"name": "Amit", "marks": 90},
{"name": "Sara", "marks": 85}
]

for student in students:
print(student["name"], student["marks"])


Output

Amit 90
Sara 85


This is very similar to how records are stored before converting them into a Pandas DataFrame.

๐Ÿ”น 9. Common Mistakes

โŒ Trying to Modify a Tuple

colors = ("Red", "Green")
colors[0] = "Blue"


This raises a TypeError because tuples are immutable.

โŒ Accessing a Missing Dictionary Key

student = {"name": "John"}
print(student["age"])


This raises a KeyError.

A safer approach:

print(student.get("age"))


๐ŸŽฏ Practice Questions

1. Create a list of five cities and print the third city.

2. Create a tuple containing the days of the week.

3. Remove duplicate numbers from a list using a set.

4. Create a dictionary containing your name, age, and profession.

5. Print all keys and values of a dictionary using a loop.

๐ŸŽฏ Key Takeaways

โœ… Lists are ordered and mutable.

โœ… Tuples are ordered and immutable.

โœ… Sets store only unique values.

โœ… Dictionaries store data as key-value pairs.

โœ… Dictionaries and Lists are the most commonly used data structures in Data Science.

Mastering these four data structures will make it much easier to work with datasets, APIs, JSON files, and machine learning projects.

Double Tap โค๏ธ For Part-8
โค8
๐Ÿš€ ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—™๐—ฅ๐—˜๐—˜ ๐—ง๐—ฒ๐—ฐ๐—ต ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ | ๐Ÿฑ ๐— ๐˜‚๐˜€๐˜-๐——๐—ผ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐ŸŽ“

Cisco offers learning opportunities covering some of the most valuable foundations for careers in Cybersecurity, Networking, Linux and IoT.

โœ… Beginner-Friendly Tech Skills
โœ… Learn In-Demand IT Concepts
โœ… Build Practical Knowledge
โœ… Strengthen Your Resume
โœ… Great for Students & Freshers

๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:- 

https://pdlink.in/4fhCSKo

๐Ÿ”ฅ Learn from Cisco โ€ข Build Skills โ€ข Upgrade Your Resume โ€ข Get Career-Ready!
โค1
Which Python data structure is ordered, mutable, and allows duplicate values?
Anonymous Quiz
9%
A) Set
24%
B) Tuple
60%
C) List
8%
D) Dictionary
๐Ÿ‘2โค1
Which data structure stores only unique elements?
Anonymous Quiz
8%
A) List
29%
B) Tuple
45%
C) Set
18%
D) Dictionary
๐Ÿ‘2โค1
What will be the output of the following code?
numbers = {1, 2, 2, 3, 4, 4}
print(len(numbers))
Anonymous Quiz
33%
4
15%
5
50%
6
2%
7
โค5
๐—”๐—œ & ๐——๐—ฎ๐˜๐—ฎ ๐—ฆ๐—ฐ๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ (๐—ก๐—ผ ๐—–๐—ผ๐—ฑ๐—ถ๐—ป๐—ด ๐—ก๐—ฒ๐—ฒ๐—ฑ๐—ฒ๐—ฑ)

Apply Now๐Ÿ‘‰:- https://pdlink.in/4aYWald

By E&ICT Academy, IIT Roorkee

Batch Closing Soon - 26th July 2026
๐Ÿš€ Data Science Roadmap 2026

๐Ÿ“˜ Phase 1: Programming Fundamentals

๐Ÿ Topic 8: Python List Comprehensions

Welcome back! ๐Ÿ‘‹

In the previous lesson, you learned about Python's built-in data structuresโ€”Lists, Tuples, Sets, and Dictionaries.

Now it's time to learn one of Python's most elegant and frequently used features: List Comprehensions.

List comprehensions provide a concise and readable way to create, filter, and transform lists. They are widely used in Data Science, Machine Learning, data preprocessing, and coding interviews.

๐Ÿ”น 1. What is a List Comprehension?

A list comprehension is a compact way to create a new list by applying an expression to each item in an iterable (such as a list, tuple, or range).

Instead of writing multiple lines with a loop, you can accomplish the same task in a single line.

General Syntax

new_list = [expression for item in iterable]

๐Ÿ”น 2. Creating a List Using a Loop

numbers = []
for i in range(5):
numbers.append(i)
print(numbers)


Output

[0, 1, 2, 3, 4]


๐Ÿ”น 3. Creating the Same List Using List Comprehension

numbers = [i for i in range(5)]
print(numbers)


Output

[0, 1, 2, 3, 4]  


Notice how the code is shorter and easier to read.

๐Ÿ”น 4. Performing Calculations

Create a list of squares.

squares = [x ** 2 for x in range(1, 6)]
print(squares)


Output

[1, 4, 9, 16, 25]


๐Ÿ”น 5. Using Conditions

You can filter elements while creating a list.

Example: Even Numbers

even_numbers = [x for x in range(1, 11) if x % 2 == 0]
print(even_numbers)


Output

[2, 4, 6, 8, 10]


๐Ÿ”น 6. Converting Strings

Convert all names to uppercase.

names = ["rahul", "deepak", "anita"]
upper_names = [name.upper() for name in names]
print(upper_names)


Output

['RAHUL', 'DEEPAK', 'ANITA']


๐Ÿ”น 7. Using Conditional Expressions

Replace negative numbers with zero.

numbers = [5, -2, 8, -1, 3]
updated = [0 if x < 0 else x for x in numbers]
print(updated)


Output

[5, 0, 8, 0, 3]


๐Ÿ”น 8. Nested List Comprehension

Create a multiplication table.

table = [[i * j for j in range(1, 6)] for i in range(1, 4)]
print(table)


Output

[[1, 2, 3, 4, 5],
[2, 4, 6, 8, 10],
[3, 6, 9, 12, 15]]


๐Ÿ”น 9. Real-World Data Science Example

Suppose you have a list of sales amounts.

sales = [1200, 850, 1500, 600, 2000]
high_sales = [sale for sale in sales if sale > 1000]
print(high_sales)


Output

[1200, 1500, 2000] 


This technique is commonly used while cleaning and filtering datasets before analysis.

๐Ÿ”น 10. Benefits of List Comprehensions

โœ… Shorter code

โœ… Easier to read

โœ… Faster than traditional loops in many cases

โœ… Widely used in Data Science and Machine Learning

๐Ÿ”น 11. Common Mistakes

โŒ Forgetting the Expression

numbers = [for i in range(5)]  # SyntaxError


Correct:

numbers = [i for i in range(5)]


โŒ Incorrect Order of "if"

numbers = [if x % 2 == 0 x for x in range(10)]  # SyntaxError


Correct:

numbers = [x for x in range(10) if x % 2 == 0]
โค7๐Ÿ‘1
๐ŸŽฏ Practice Questions

1. Create a list of numbers from 1 to 20.

2. Create a list containing the squares of numbers from 1 to 10.

3. Create a list containing only odd numbers from 1 to 20.

4. Convert a list of names to lowercase.

5. Replace all negative values in a list with zero using a list comprehension.

๐ŸŽฏ Key Takeaways

โœ… List comprehensions provide a concise way to create lists.

โœ… They combine loops and expressions into a single line.

โœ… You can filter data using "if" conditions.

โœ… Conditional expressions allow values to be modified during list creation.

โœ… List comprehensions are widely used in data cleaning, feature engineering, and machine learning workflows.

Mastering list comprehensions will help you write cleaner, more Pythonic code and prepare you for technical interviews and real-world Data Science projects.

Double Tap โค๏ธ For Part-9
โค8
๐Ÿš€ ๐—–๐—ถ๐˜€๐—ฐ๐—ผ ๐—™๐—ฅ๐—˜๐—˜ ๐—ง๐—ฒ๐—ฐ๐—ต ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ | ๐Ÿฑ ๐— ๐˜‚๐˜€๐˜-๐——๐—ผ ๐—–๐—ผ๐˜‚๐—ฟ๐˜€๐—ฒ๐˜€ ๐ŸŽ“

Cisco offers learning opportunities covering some of the most valuable foundations for careers in Cybersecurity, Networking, Linux and IoT.

โœ… Beginner-Friendly Tech Skills
โœ… Learn In-Demand IT Concepts
โœ… Build Practical Knowledge
โœ… Strengthen Your Resume
โœ… Great for Students & Freshers

๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:- 

https://pdlink.in/4fhCSKo

๐Ÿ”ฅ Learn from Cisco โ€ข Build Skills โ€ข Upgrade Your Resume โ€ข Get Career-Ready!
โค2
๐Ÿ’ฐ 3 years of experience. Still waiting for a salary jump?

Experience alone doesn't guarantee growth.

Learning in-demand skills can help you stay competitive in today's job market.

That's why people are joining E&ICT Academy IIT Roorkee's AI & ML Program.

โœ… 6 Months | Online | Open for all backgrounds
โœ… Learn from IIT professors & industry mentors
โœ… Flipkart & Mamaearth projects
โœ… Placement support through Masai's network of 5000+ companies

๐Ÿ—“ Entrance Test: 26th July

๐Ÿ”—
https://tinyurl.com/DS-26Jul-006
โค5
๐Ÿš€ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ ๐—ฆ๐—ค๐—Ÿ ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜! ๐Ÿ—„๏ธ๐Ÿ’ป

Start learning SQL with these 100% FREE resources and build one of the most in-demand skills in tech!

โœ… Beginner-Friendly SQL Tutorials
โœ… FREE Online SQL Courses
โœ… Interactive SQL Practice Platforms
โœ… Real-World Database Projects
โœ… Interview Preparation Resources
โœ… Hands-on Exercises & Challenges

๐—˜๐—ป๐—ฟ๐—ผ๐—น๐—น ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡:- 

https://pdlink.in/4yLrNci

๐Ÿš€ Start your SQL journey today and unlock exciting career opportunities!
โค4