0% found this document useful (0 votes)
16 views3 pages

Assessment of Sumit

The document contains a series of programming exercises focused on list manipulation in Python. It includes tasks such as appending and removing elements, finding the largest and smallest numbers, reversing lists, splitting lists, generating squares, filtering even numbers, and removing duplicates. Additionally, it demonstrates creating a matrix and flattening nested lists.

Uploaded by

75227sumit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views3 pages

Assessment of Sumit

The document contains a series of programming exercises focused on list manipulation in Python. It includes tasks such as appending and removing elements, finding the largest and smallest numbers, reversing lists, splitting lists, generating squares, filtering even numbers, and removing duplicates. Additionally, it demonstrates creating a matrix and flattening nested lists.

Uploaded by

75227sumit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ASSESSMENT OF SUMIT

# ASSESSMENT QUESTION 1
numbers = [5, 10, 15, 20, 25]
numbers.append(30)
numbers.pop(1)
numbers[-1] = 35
print("Length of the list:", len(numbers))
print("Updated list:", numbers)

# ASSESSMENT QUESTION

# Write a program to find the largest and smallest numbers in a


list.

numbers = [10, 25, 5, 40, 15]


largest = max(numbers)
smallest = min(numbers)
print("Largest number:", largest)
print("Smallest number:", smallest)

# Create two lists: one containing names and the other


containing their corresponding ages. Print each

names = ["Sumit", "Ridhima", "Vijay", "Vishal"]


ages = [25, 30, 22, 28]

for i in range(len(names)):
print(names[i], "is", ages[i], "years old")

#Reverse a list without using the reverse() method.


# Create a list
numbers = [10, 20, 30, 40, 50]

reversed_list = numbers[::-1]

print("Reversed list:", reversed_list)

#Assessment List slicing Q1


# Create a list of numbers
numbers = [10, 20, 30, 40, 50, 60, 70, 80]
first_three = numbers[:3]
last_two = numbers[-2:]
every_second = numbers[::2]
print("First 3 elements:", first_three)
print("Last 2 elements:", last_two)
print("Every second element:", every_second)
#Write a program to split a list into two halves.
# Create a list of numbers
numbers = [10, 20, 30, 40, 50, 60]
mid = len(numbers) // 2
first_half = numbers[:mid]
second_half = numbers[mid:]
print("First half:", first_half)
print("Second half:", second_half)

# Generate a list of squares of numbers from 1 to 10 using list


comprehension

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


print("List of squares:", squares)

# Filter out all even numbers from a given list using list
comprehension.

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

evens = [x for x in numbers if x % 2 == 0]

print("Even numbers:", evens)

#Create a new list that contains only the words with more than 3
characters from an existing list of strings.

words = ["cat", "apple", "bat", "banana", "dog", "elephant", "Sumit",


"Hat", "Ridhima", "Vishal"]

long_words = [word for word in words if len(word) > 3]

print("Words with more than 3 characters:", long_words)

#Create a 3x3 matrix as a nested list and print each row on a new
line
# Create a 3x3 matrix (nested list)
matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]

for row in matrix:


print(row)
# Flatten a nested list into a single list using either loops or list
comprehension.
nested_list = [[1, 2], [3, 4], [5, 6]]
flat_list = []

for sublist in nested_list:


for item in sublist:
flat_list.append(item)

print(flat_list)

#Write a program to remove duplicates from a list while


maintaining the original order.
numbers = [1, 2, 2, 3, 4, 4, 5, 5, 56, 88, 88, 95, 5]
unique_numbers = []

for num in numbers:


if num not in unique_numbers:
unique_numbers.append(num)

print(unique_numbers)

Question 13
list1 = [1, 2, 3, 4, 5]
list2 = [3, 4, 5, 6, 7]

common_elements = []

for item in list1:


if item in list2:
common_elements.append(item)

print(common_elements)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy