0% found this document useful (0 votes)
3 views

Python_list_questions

The document contains a series of Python programming exercises categorized into Beginner, Intermediate, and Advanced levels. Each exercise provides a specific task, such as finding the maximum element in a list, summing elements, or removing duplicates, along with example inputs and expected outputs. The tasks aim to enhance programming skills in Python through practical applications.

Uploaded by

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

Python_list_questions

The document contains a series of Python programming exercises categorized into Beginner, Intermediate, and Advanced levels. Each exercise provides a specific task, such as finding the maximum element in a list, summing elements, or removing duplicates, along with example inputs and expected outputs. The tasks aim to enhance programming skills in Python through practical applications.

Uploaded by

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

Beginner

1.​ Write a Python program to find the maximum element in a list of numbers without
max functions
numbers = [10, 20, 4, 45, 99]
The maximum element is: 99

2.​ Write a Python program to sum all the elements in a list of numbers.
a.​ numbers = [10, 20, 30, 40]
b.​ The sum of all elements is: 100
3.​ Write a Python program to reverse a list without reverse or slicing operator
a.​ numbers = [1, 2, 3, 4, 5]
b.​ Reversed list: [5, 4, 3, 2, 1]
4.​ Write a Python program to sort a list in ascending order without sort functions
5.​ Write a Python program to remove duplicates from a list while maintaining the order
of elements.
a.​ numbers = [1, 2, 2, 3, 4, 4, 5]
b.​ List after removing duplicates: [1, 2, 3, 4, 5]
6.​ Write a Python program to find all pairs of numbers in a list that add up to a specific
target sum.
a.​ numbers = [1, 2, 3, 4, 3, 5, 6] target_sum = 6
b.​ Pairs that add up to 6: [(3, 3), (2, 4), (1, 5)]
7.​ Write a Python program to flatten a nested list (list within lists) into a single list.
a.​ nested_list = [1, [2, 3], [4, [5, 6], 7], 8]
b.​ Flattened list: [1, 2, 3, 4, 5, 6, 7, 8]
8.​ Write a Python program to find the sum of the elements in a list, excluding the largest
and smallest element. Don’t use max or min functions
a.​ numbers = [1, 2, 3, 4, 5]
b.​ Sum excluding the largest and smallest element: 9

Intermediate

9.​ Write a Python program to check if a list is a palindrome (reads the same backward
as forward) using two pointer approach
a.​ numbers = [1, 2, 3, 2, 1]
b.​ True
10.​Write a function to remove duplicate elements from a list.
a.​ numbers = [1, 2, 3, 2, 4, 5, 1, 6]
b.​ [1, 2, 3, 4, 5, 6]
11.​ Find Common Elements in Two Lists
a.​ list1 = [1, 2, 3, 4, 5]
b.​ list2 = [3, 4, 5, 6, 7]
c.​ Result: [3, 4, 5]
12.​Find the Longest Word in a List
a.​ words = ["apple", "banana", "strawberry", "kiwi"]
b.​ Strawberry
13.​Find Missing Number in a List

Advanced

14.​ Find Missing Number in a List


​ You are given a list of n-1 numbers in the range 1 to n. One number is missing
from the sequence. Find the missing number.
a.​ numbers = [1, 2, 4, 5, 6]
b.​ 3
15.​Find the First Non-Repeating Element
Given a list of integers, find the first element that appears only once.
a.​ numbers = [4, 5, 1, 2, 0, 4, 5, 2]
b.​ Expected Output: 1
16.​Move All Zeros to the End
Given a list of integers, move all zeros to the end while maintaining the relative order
of non-zero elements. Don’t use any inbuilt functions
a.​ numbers = [0, 1, 0, 3, 12]
b.​ [1, 3, 12, 0, 0]
17.​Find Elements Greater Than Their Left Neighbor
a.​ numbers = [1, 3, 2, 6, 5, 8, 7]
b.​ [3, 6, 8]
18.​Find Triplets That Sum to Zero
Given a list of numbers, find all unique triplets (a, b, c) such that a + b + c = 0.
a.​ numbers = [-1, 0, 1, 2, -1, -4]
b.​ Expected Output: [(-1, -1, 2), (-1, 0, 1)]

You might also like