Batch 11 Python
Batch 11 Python
(Autonomous)
Bharathi Salai, Ramapuram, Chennai – 89
Department of Computer Science Engineering SDG GOAL NO.4
Group Presentation
Batch -XI
TOPIC : Lists Methods and List Comprehension in Python
TEAM MEMBERS
310624104170- MADHAN KUMAR J
310624104171- MADHAN M
310624104172 - MADHAN V M
310624104173- MADHUMITHA G R
310624104174- MADHUMITHA V
OUTCOMES OF SDG GOALS:
• Enhances Problem-Solving Skills: List methods and comprehension train learners to approach
tasks systematically, breaking problems into smaller, solvable pieces, a critical component of
quality education.
• Fosters Logical Thinking: By applying conditions and iterative logic, students learn structured
thinking, essential for both programming and general analytical problem-solving.
• Promotes Efficiency: List comprehension provides a compact, efficient way to handle data,
teaching students how to write clean, optimized code—a valuable skill in software development
and data science.
• Encourages Creativity: The flexibility of these tools allows students to explore multiple solutions
to a problem, stimulating innovation and adaptability.
• Prepares for Interdisciplinary Applications: These skills are foundational for fields like data
analysis, AI, and scientific computing, preparing students for careers in diverse domains.
• Supports Inclusive Education: Python's simplicity, paired with these features, makes
programming accessible to learners worldwide, bridging gaps in technical education and
contributing to equity in learning opportunities.
Lists, Methods, and
List Comprehension in
Python
Join us on a journey through the world of Python lists,
discovering their power and flexibility in crafting
dynamic and efficient code.
What are Lists in Python?
Ordered Sequences Mutable Versatile
Lists are ordered collections Lists are mutable, meaning Lists can store different
of items, meaning that the you can change their contents data types, including
order in which you add items after they've been created by numbers, strings, and even
is preserved. For example: adding, removing, or other lists, making them
modifying items. Here's an highly versatile. Consider
my_list = [1, "hello", example: this:
mixed_list = [1, "apple",
3.14, True] my_list = [1, 2, 3] [2, 3], 4.5]
print(my_list) # Output: my_list[0] = 10 print(mixed_list) #
[1, "hello", 3.14, True] my_list.append(4) Output: [1, "apple", [2,
print(my_list[0]) # print(my_list) # Output: 3], 4.5]
Output: 1 [10, 2, 3, 4]
Common List Operations and Methods
append() insert() remove()
Adds an element to the end of a list. Inserts an element at a specified index. Removes the first occurrence of a specified element.
reverse()
Reverses the order of elements in the list.
my_list = [1, 2, 3]
my_list.reverse()
print(my_list) # Output: [3, 2, 1]
Common List Operations and Methods
Input
OUTPUT
List Comprehension in python
List comprehension in Python is a concise and powerful way to create, filter, and transform lists
using a single line of code. It combines the functionality of loops and conditional statements
into a readable and efficient syntax.
item: Each element from the iterable (e.g., list, range, string).
OUTPUT
Comparison and Practical Applications
* List comprehensions enhance code readability and reduce boilerplate code, making them a
preferred choice for many developers.
* While list methods provide granular control for in-place modifications and specific operations,
list comprehension excels in creating new lists based on existing ones.
For example:
1. Use list methods when you need to modify an existing list, such as appending elements or removing dup
2. Use list comprehension for transforming or filtering data in a declarative and concise way.
3. Practical applications of these tools include data processing, building algorithms, and
solving problems efficiently. For instance, sorting a list of numbers, extracting specific
elements, or converting raw data into structured formats.
Real-Time Applications of List Methods and Comprehensions
1. Filtering Data (e.g., Extracting Even Numbers) 2.Removing Specific Items (e.g., Removing Negative Numbers)
# List of numbers # List of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] numbers = [-1, 2, -3, 4, -5, 6]
# Using list comprehension to extract even numbers # Using list comprehension to remove negative numbers
even_numbers = [num for num in numbers if num % 2 == 0]
positive_numbers = [num for num in numbers if num >= 0]
print(even_numbers)
print(positive_numbers)
OUTPUT OUTPUT
[2, 4, 6, 8]
[2, 4, 6]
OUTPUT
['hello', 'world', 'python', 'datascience']
Conclusion
* Both list methods and list comprehensions are indispensable tools in Python.
* While list methods provide a detailed and explicit approach to list manipulation
list comprehension offers a streamlined syntax for creating new lists.
* Mastering these concepts not only simplifies data manipulation but also enhances
the clarity and efficiency of Python programs.
THANK
YOU