Python Assess2 for DA
Python Assess2 for DA
List Slicing
1. Given a list of numbers, extract:
o The first 3 elements.
o The last 2 elements.
o Every second element from the list.
2. Write a program to split a list into two halves.
List Comprehensions
1. Generate a list of squares of numbers from 1 to 10 using list comprehension.
2. Filter out all even numbers from a given list using list comprehension.
3. Create a new list that contains only the words with more than 3 characters from an existing list of
strings.
Nested Lists
1. Create a 3x3 matrix as a nested list and print each row on a new line.
2. Flatten a nested list into a single list using either loops or list comprehension.
Advanced Challenges
1. Write a program to remove duplicates from a list while maintaining the original order.
2. Given two lists, create a new list containing only the common elements between them.
3. Sort a list of tuples based on the second element in each tuple (e.g., [(1, 3), (4, 2), (5, 1)] →
[(5, 1), (4, 2), (1, 3)]).
These exercises cover foundational concepts like indexing, slicing, comprehensions, and nested lists, which are
essential for mastering Python lists!