Python Lists Practice Questions with Solutions

Lists are one of the most useful data structures in Python. They allow you to store multiple values in a single variable and perform operations such as adding, removing, updating, sorting, and searching elements. In this Python Lists practice questions with solutions set, you’ll solve beginner-friendly list programs with complete solutions.


1. Python Program to Create and Print a List

Problem Statement

Write a Python program to create a list of five fruits and print the complete list.

Python Solution

fruits = ["Apple", "Banana", "Mango", "Orange", "Grapes"]

print(fruits)

Sample Output

['Apple', 'Banana', 'Mango', 'Orange', 'Grapes']

Explanation

A list stores multiple values in a single variable using square brackets [].

Concepts Covered

  • Creating Lists
  • List Syntax

2. Python Program to Access List Elements

Problem Statement

Write a Python program to print the first, third, and last element of a list.

Python Solution

colors = ["Red", "Blue", "Green", "Yellow", "Black"]

print("First:", colors[0])
print("Third:", colors[2])
print("Last:", colors[-1])

Sample Output

First: Red
Third: Green
Last: Black

Explanation

List elements are accessed using index numbers. Negative indexing starts from the end of the list.

Concepts Covered

  • List Indexing
  • Negative Indexing

3. Python Program to Add an Item to a List

Problem Statement

Write a Python program to add "Python" to the end of a list.

Python Solution

courses = ["Java", "C++", "JavaScript"]

courses.append("Python")

print(courses)

Sample Output

['Java', 'C++', 'JavaScript', 'Python']

Explanation

The append() method adds a new element at the end of a list.

Concepts Covered

  • append()

4. Python Program to Insert an Item at a Specific Position

Problem Statement

Write a Python program to insert "HTML" at index 1.

Python Solution

courses = ["Python", "Java", "C++"]

courses.insert(1, "HTML")

print(courses)

Sample Output

['Python', 'HTML', 'Java', 'C++']

Explanation

The insert() method adds an element at the specified position.

Concepts Covered

  • insert()

5. Python Program to Remove an Item from a List

Problem Statement

Write a Python program to remove "Orange" from the list.

Python Solution

fruits = ["Apple", "Orange", "Banana", "Mango"]

fruits.remove("Orange")

print(fruits)

Sample Output

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

Explanation

The remove() method deletes the specified element from the list.

Concepts Covered

  • remove()

6. Python Program to Find the Largest Number in a List

Problem Statement

Write a Python program to find the largest number in a list.

Python Solution

numbers = [25, 60, 18, 95, 42]

print("Largest Number:", max(numbers))

Sample Output

Largest Number: 95

Explanation

The max() function returns the largest value in the list.

Concepts Covered

  • max()

7. Python Program to Find the Sum of All List Elements

Problem Statement

Write a Python program to calculate the sum of all numbers in a list.

Python Solution

numbers = [10, 20, 30, 40, 50]

print("Sum:", sum(numbers))

Sample Output

Sum: 150

Explanation

The sum() function calculates the total of all numeric values in the list.

Concepts Covered

  • sum()

8. Python Program to Sort a List in Ascending Order

Problem Statement

Write a Python program to sort a list in ascending order.

Python Solution

numbers = [45, 12, 78, 23, 9]

numbers.sort()

print(numbers)

Sample Output

[9, 12, 23, 45, 78]

Explanation

The sort() method arranges list elements in ascending order.

Concepts Covered

  • sort()

9. Python Program to Reverse a List

Problem Statement

Write a Python program to reverse the elements of a list.

Python Solution

numbers = [10, 20, 30, 40, 50]

numbers.reverse()

print(numbers)

Sample Output

[50, 40, 30, 20, 10]

Explanation

The reverse() method changes the order of list elements.

Concepts Covered

  • reverse()

10. Python Program to Count the Occurrences of an Element in a List

Problem Statement

Write a Python program to count how many times a specific element appears in a list.

Python Solution

numbers = [10, 20, 30, 20, 40, 20]

count = numbers.count(20)

print("Occurrences:", count)

Sample Output

Occurrences: 3

Explanation

The count() method returns the number of times an element appears in the list.

Concepts Covered

  • count()

11. Python Program to Find the Second Largest Element in a List

Problem Statement

Write a Python program to find the second largest element in a list without using the sort() function.

Python Solution

numbers = [25, 18, 42, 67, 91, 56]

largest = second = float('-inf')

for num in numbers:
    if num > largest:
        second = largest
        largest = num
    elif largest > num > second:
        second = num

print("Second Largest Element:", second)

Sample Output

Second Largest Element: 67

Explanation

The program traverses the list only once while keeping track of the largest and second largest values.

Concepts Covered

  • Lists
  • for Loop
  • Conditional Statements
  • List Traversal

12. Python Program to Remove Duplicate Elements from a List

Problem Statement

Write a Python program to remove duplicate elements from a list while preserving the original order.

Python Solution

numbers = [10, 20, 10, 30, 40, 20, 50]

unique = []

for num in numbers:
    if num not in unique:
        unique.append(num)

print("Original List:", numbers)
print("List Without Duplicates:", unique)

Sample Output

Original List: [10, 20, 10, 30, 40, 20, 50]

List Without Duplicates:
[10, 20, 30, 40, 50]

Explanation

The program checks whether each element already exists in the new list before adding it.

Concepts Covered

  • Lists
  • append()
  • Membership Operator
  • for Loop

13. Python Program to Merge Two Sorted Lists into One Sorted List

Problem Statement

Write a Python program to merge two sorted lists into a single sorted list.

Python Solution

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

merged = list1 + list2
merged.sort()

print("Merged Sorted List:")
print(merged)

Sample Output

Merged Sorted List:
[1, 2, 3, 4, 5, 6, 7, 8]

Explanation

The two lists are combined using the + operator and then sorted using the sort() method.

Concepts Covered

  • List Concatenation
  • sort()
  • List Methods

14. Python Program to Find Common Elements Between Two Lists

Problem Statement

Write a Python program to find the common elements present in two lists.

Python Solution

list1 = [10, 20, 30, 40, 50]
list2 = [30, 40, 60, 70]

common = []

for item in list1:
    if item in list2:
        common.append(item)

print("Common Elements:", common)

Sample Output

Common Elements: [30, 40]

Explanation

The program compares both lists and stores only the common elements in a new list.

Concepts Covered

  • Lists
  • Membership Operator
  • append()
  • List Comparison

15. Python Program to Rotate a List by N Positions

Problem Statement

Write a Python program to rotate the elements of a list to the left by a specified number of positions.

Python Solution

numbers = [10, 20, 30, 40, 50, 60]

n = int(input("Enter rotation count: "))

n = n % len(numbers)

rotated = numbers[n:] + numbers[:n]

print("Rotated List:")
print(rotated)

Sample Output

Enter rotation count: 2

Rotated List:
[30, 40, 50, 60, 10, 20]

Explanation

The program uses list slicing to divide the list into two parts and then joins them in rotated order.

Concepts Covered

  • List Slicing
  • List Concatenation
  • User Input

Frequently Asked Questions (FAQs)

1. What is a list in Python?

A list is an ordered, mutable collection that can store multiple items of different data types. Lists are created using square brackets [].

Example:

numbers = [10, 20, 30, 40]

2. Are Python lists mutable?

Yes. Lists are mutable, meaning you can add, remove, update, and reorder elements after the list has been created.

Example:

fruits = ["Apple", "Banana", "Mango"]

fruits.append("Orange")

print(fruits)

3. What are the most commonly used list methods in Python?

Some commonly used list methods include:

  • append()
  • extend()
  • insert()
  • remove()
  • pop()
  • sort()
  • reverse()
  • index()
  • count()
  • copy()
  • clear()

These methods make it easy to manipulate list data.


4. What is the difference between append() and extend()?

  • append() adds a single element to the end of a list.
  • extend() adds multiple elements from another iterable to the list.

Example:

list1 = [1, 2]

list1.append(3)
print(list1)

list1.extend([4, 5])
print(list1)

5. Why are lists important in Python?

Lists are one of the most versatile data structures in Python. They are widely used in data analysis, machine learning, web development, automation, file processing, and algorithm design. Mastering lists is essential because many real-world Python applications rely on efficient storage and manipulation of collections of data.

Chapter Summary

After completing this chapter, you have learned:

  • Creating lists
  • Accessing list elements
  • List indexing
  • Negative indexing
  • append()
  • insert()
  • remove()
  • max()
  • sum()
  • sort()
  • reverse()
  • count()

Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top