Absolutely. Here is a complete list of coding questions focused only on list and tuple in Python, covering all levels of difficulty (beginner, intermediate, advanced) — ideal for interviews:


Python List and Tuple Coding Interview Questions (100+ Total)


🔰 Beginner (Basic Operations)

  1. Create a list of first 10 natural numbers.
  2. Find the length of a list.
  3. Access the third element of a list.
  4. Slice a list from index 2 to 5.
  5. Append an element to a list.
  6. Insert an element at index 2.
  7. Remove an element by value.
  8. Remove an element by index.
  9. Reverse a list using slicing.
  10. Sort a list of integers.
  11. Create a tuple of 5 fruits.
  12. Access the last element of a tuple.
  13. Check if an element exists in a list.
  14. Count the number of times 5 appears in a list.
  15. Convert a tuple to a list.
  16. Convert a list to a tuple.
  17. Create an empty list and empty tuple.
  18. Join two lists.
  19. Join two tuples.
  20. Find the index of an element in a list.

🧩 Intermediate (Logic + Built-in functions)

  1. Remove duplicates from a list.
  2. Find the maximum and minimum in a list.
  3. Create a list from 1 to 100 using list comprehension.
  4. Filter even numbers from a list.
  5. Filter numbers divisible by 3 or 5.
  6. Square all elements using list comprehension.
  7. Create a list of tuples with numbers and their squares.
  8. Flatten a 2D list into a 1D list.
  9. Zip two lists into a list of tuples.
  10. Unzip a list of tuples into two lists.
  11. Rotate a list left by 2 positions.
  12. Find the second largest number in a list.
  13. Find the third smallest number in a list.
  14. Remove all falsy values from a list (None, 0, '', etc.)
  15. Split a list into chunks of size 3.
  16. Find the most frequent element in a list.
  17. Check if all elements in list are unique.
  18. Replace all occurrences of a value with another.
  19. Count occurrences of each element in a list.
  20. Merge two sorted lists into one sorted list.

💡 Problem Solving (Application)

  1. Check if a list is a palindrome.
  2. Reverse a tuple.
  3. Find all pairs in list whose sum equals a given value.
  4. Find common elements in two lists.
  5. Find elements present in one list but not in another.
  6. Remove all even indexed elements from a list.
  7. Create a frequency dictionary from list.
  8. Group words by their first letter from a list of strings.
  9. Sort a list of tuples by second element.
  10. Remove empty strings from a list.
  11. Find difference between max and min in list of tuples.
  12. Group a list into sublists of N elements.
  13. Find duplicates and return only once.
  14. Replace first and last element in list.
  15. Swap every pair of elements in a list.
  16. Convert a list of strings to list of ints.
  17. Remove negative numbers from list.
  18. Replace negative numbers with 0.
  19. Convert list of tuples to dictionary.
  20. Split list based on a condition.

🧠 Advanced Logic / Tricky

  1. Find longest increasing subsequence in a list.
  2. Find the intersection of multiple lists.
  3. Find the union of multiple lists.
  4. Check if two lists are anagrams.
  5. Sort list of tuples based on sum of tuple elements.
  6. Sort a list of tuples by custom key (e.g., last char of first element).
  7. Write a function to flatten a deeply nested list.
  8. Generate all permutations of a list.
  9. Generate all combinations of a list of length k.
  10. Implement custom sort using lambda.
  11. Find element which appears exactly once (others appear twice).
  12. Rotate list in place (without using extra space).
  13. Replace every element with the next greatest element.
  14. Partition a list into even and odd numbers.
  15. Find product of all elements except current index.
  16. Rearrange list so that positive and negative alternate.
  17. Find contiguous subarray with maximum sum (Kadane’s algorithm).
  18. Merge k sorted lists into one.
  19. Count triplets in list that sum to 0.
  20. Find all subsets of a list.

🧪 Tuple Specific Logic

  1. Find length of longest tuple in list of tuples.
  2. Check if all tuples in a list are of equal length.
  3. Count tuples where first and last element are same.
  4. Sort list of tuples by first element.
  5. Sort list of tuples by second element descending.
  6. Create a tuple of squares from 1 to 10.
  7. Check if a tuple is nested.
  8. Find common elements in list of tuples.
  9. Convert a list of strings to list of character tuples.
  10. Access nested tuple values.

🔐 Pattern-based Challenges

  1. Return all elements before a specific element in list.
  2. Check if list contains three consecutive even numbers.
  3. Find longest sublist without repeating elements.
  4. Remove K consecutive duplicate elements from a list.
  5. Implement a stack using list.
  6. Implement a queue using list.
  7. Count how many times a pattern appears in list.
  8. Find the index of first duplicate.
  9. Find the last non-zero number in list.
  10. Count how many numbers end with 5 in a list.

💡 Pro Tip: Use enumerate(), zip(), sorted(), collections.Counter, itertools, and lambda in Python to solve most intermediate to advanced problems efficiently.

Absolutely. Below is a comprehensive list of coding problems focused entirely on Python list and tuple, with:

  • ✅ Problem Statement
  • 🧠 Difficulty Level
  • 🏷️ Interview Tags
  • 🧾 Code Solution (Clean & Readable)

✅ 100 Python List & Tuple Problems for Interviews (with Tags & Solutions)


1. Find the sum of all elements in a list

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: list, sum
nums = [1, 2, 3, 4, 5]
print(sum(nums))

2. Find the maximum and minimum element in a list

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: list, max, min
lst = [3, 7, 2, 9, 1]
print(max(lst), min(lst))

3. Remove duplicates from a list

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: list, set
lst = [1, 2, 2, 3, 4, 4, 5]
print(list(set(lst)))

4. Check if two lists have any common elements

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, set, intersection
a = [1, 2, 3]
b = [4, 5, 2]
print(bool(set(a) & set(b)))

5. Flatten a nested list

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, recursion
from itertools import chain
nested = [[1, 2], [3, 4], [5]]
print(list(chain.from_iterable(nested)))

6. Find all even numbers in a list

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: list, filter
lst = [1, 2, 3, 4, 5, 6]
print([x for x in lst if x % 2 == 0])

7. Find common elements from two tuples

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: tuple, set
a = (1, 2, 3)
b = (2, 3, 4)
print(tuple(set(a) & set(b)))

8. Reverse a tuple

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: tuple, slicing
t = (1, 2, 3)
print(t[::-1])

9. Sort a list of tuples by the second item

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: tuple, lambda, sort
data = [(1, 3), (2, 2), (4, 1)]
print(sorted(data, key=lambda x: x[1]))

10. Check if list is sorted

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: list, comparison
lst = [1, 2, 3, 4]
print(lst == sorted(lst))

11. Rotate a list left by one

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, slice
lst = [1, 2, 3, 4]
print(lst[1:] + lst[:1])

12. Find second largest element in a list

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, sort
lst = [4, 1, 7, 3]
print(sorted(set(lst))[-2])

13. Find frequency of each element in list

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, dict, collections.Counter
from collections import Counter
lst = [1, 2, 2, 3, 1]
print(dict(Counter(lst)))

14. Find all pairs in list that sum to a target

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, two-pointer
lst = [2, 4, 3, 5, 6]
target = 7
print([(i, j) for i in lst for j in lst if i + j == target and i != j])

15. Unpack tuple into variables

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: tuple, unpacking
a = (1, 2, 3)
x, y, z = a
print(x, y, z)

16. Swap first and last element in list

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: list, swap
lst = [1, 2, 3, 4]
lst[0], lst[-1] = lst[-1], lst[0]
print(lst)

17. Convert list of tuples into dictionary

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, dict, tuple
lst = [('a', 1), ('b', 2)]
print(dict(lst))

18. Check if list is palindrome

  • 🧠 Difficulty: Easy
  • 🏷️ Tags: list, palindrome
lst = [1, 2, 3, 2, 1]
print(lst == lst[::-1])

19. Merge two sorted lists into one

  • 🧠 Difficulty: Medium
  • 🏷️ Tags: list, merge, two-pointer
a = [1, 3, 5]
b = [2, 4, 6]
merged = sorted(a + b)
print(merged)

20. Generate all permutations of a list

  • 🧠 Difficulty: Hard
  • 🏷️ Tags: list, itertools.permutations
from itertools import permutations
lst = [1, 2, 3]
print(list(permutations(lst)))

Absolutely. Here’s a comprehensive list of 80+ coding problems focused on Python Lists and Tuples, all levels of difficulty, interview-ready, and tagged. Each comes with a code snippet and difficulty tag.


✅ Python List and Tuple Coding Problems — Full Set with Tags and Solutions


🔹 BASIC LEVEL

  1. Sum of all elements in a list
    Tag: List, Loop
nums = [1, 2, 3, 4]
print(sum(nums))
  1. Find the largest number in a list
    Tag: List, max
nums = [4, 7, 2]
print(max(nums))
  1. Check if a list is empty
    Tag: List, Condition
lst = []
print("Empty" if not lst else "Not Empty")
  1. Count occurrences of an element in list
    Tag: List, count
lst = [1, 2, 2, 3]
print(lst.count(2))
  1. Check if all elements are even
    Tag: List, all, lambda
lst = [2, 4, 6]
print(all(x % 2 == 0 for x in lst))
  1. Get unique elements from a list
    Tag: Set, List
lst = [1, 2, 2, 3]
print(list(set(lst)))
  1. Flatten a nested list
    Tag: List, Nested, Flatten
nested = [[1,2], [3,4]]
flat = [item for sublist in nested for item in sublist]
print(flat)
  1. Merge two lists
    Tag: List, Merge
a = [1, 2]
b = [3, 4]
print(a + b)
  1. Find common elements
    Tag: Set, List
a = [1, 2, 3]
b = [2, 3, 4]
print(list(set(a) & set(b)))
  1. Reverse a list
    Tag: List, Slicing
lst = [1, 2, 3]
print(lst[::-1])

🔹 INTERMEDIATE LEVEL

  1. Rotate list left by k places
    Tag: List, Slicing
lst = [1, 2, 3, 4]
k = 2
print(lst[k:] + lst[:k])
  1. Find second largest number
    Tag: List, Sorting
lst = [3, 5, 2, 9]
print(sorted(set(lst))[-2])
  1. Remove duplicates and maintain order
    Tag: List, Set, Order
lst = [1, 2, 2, 3]
seen = set()
result = [x for x in lst if not (x in seen or seen.add(x))]
print(result)
  1. Find all pairs summing to target
    Tag: List, Brute Force
lst = [1, 2, 3, 4]
target = 5
pairs = [(i, j) for i in lst for j in lst if i + j == target]
print(pairs)
  1. List of cumulative sums
    Tag: List, Accumulator
from itertools import accumulate
lst = [1, 2, 3]
print(list(accumulate(lst)))
  1. Remove every kth element
    Tag: List, Loop
lst = [1,2,3,4,5,6,7]
k = 3
print([x for i, x in enumerate(lst, 1) if i % k != 0])
  1. Convert list to dictionary (index as key)
    Tag: List, Dict
lst = ['a', 'b', 'c']
print({i: val for i, val in enumerate(lst)})
  1. Split list into n parts
    Tag: List, Split
lst = [1,2,3,4,5,6]
n = 3
print([lst[i::n] for i in range(n)])
  1. Check if list is palindrome
    Tag: List, Palindrome
lst = [1, 2, 1]
print(lst == lst[::-1])
  1. Replace specific element
    Tag: List, Index
lst = [1, 2, 3]
lst[1] = 99
print(lst)

🔹 ADVANCED LEVEL

  1. Find longest increasing subsequence
    Tag: DP, List
def LIS(arr):
    from bisect import bisect_left
    sub = []
    for x in arr:
        idx = bisect_left(sub, x)
        if idx == len(sub): sub.append(x)
        else: sub[idx] = x
    return len(sub)

print(LIS([3, 10, 2, 1, 20]))
  1. Find frequency of all elements
    Tag: List, Counter
from collections import Counter
lst = [1, 2, 2, 3]
print(dict(Counter(lst)))
  1. All possible combinations of list
    Tag: List, itertools
from itertools import combinations
lst = [1, 2, 3]
for r in range(1, len(lst)+1):
    print(list(combinations(lst, r)))
  1. Cartesian product of two lists
    Tag: List, itertools
from itertools import product
a = [1, 2]
b = ['a', 'b']
print(list(product(a, b)))
  1. Chunk list into sublists of size n
    Tag: List, Chunking
lst = [1,2,3,4,5,6]
n = 2
print([lst[i:i+n] for i in range(0, len(lst), n)])
  1. Find tuples where sum is even
    Tag: Tuple, List
lst = [(1,2), (3,3), (2,2)]
print([t for t in lst if sum(t) % 2 == 0])
  1. Tuple unpacking into variables
    Tag: Tuple
t = (1, 2, 3)
a, b, c = t
print(a, b, c)
  1. Sort list of tuples by second element
    Tag: Tuple, Sort
lst = [(1, 3), (2, 1), (3, 2)]
print(sorted(lst, key=lambda x: x[1]))
  1. Get nth element from tuple in list
    Tag: List, Tuple
lst = [(1,2), (3,4), (5,6)]
n = 1
print([t[n] for t in lst])
  1. Count tuples with duplicate elements
    Tag: Tuple, List
lst = [(1,1), (2,3), (4,4)]
print(len([t for t in lst if t[0] == t[1]]))

🔹 CHALLENGE LEVEL (Logic + Python)

  1. Group elements by frequency
    Tag: List, Dict, Group
from collections import defaultdict
lst = [1,1,2,2,2,3]
group = defaultdict(list)
for x in lst:
    group[lst.count(x)].append(x)
print(group)
  1. Create a histogram from list
    Tag: Visualization, Dict
lst = [1,1,2,3]
for val in set(lst):
    print(f"{val}: {'*' * lst.count(val)}")
  1. Find median of a list
    Tag: Statistics
lst = [1, 2, 3, 4]
lst.sort()
n = len(lst)
median = (lst[n//2] + lst[(n-1)//2])/2
print(median)
  1. Find mode of a list
    Tag: Statistics
from statistics import mode
lst = [1,1,2,3]
print(mode(lst))
  1. Zipping two lists of unequal length
    Tag: zip, itertools
from itertools import zip_longest
a = [1,2]
b = ['a','b','c']
print(list(zip_longest(a,b)))

Pages: 1 2


Discover more from HintsToday

Subscribe to get the latest posts sent to your email.

Posted in

Leave a Reply

Your email address will not be published. Required fields are marked *

Discover more from HintsToday

Subscribe now to keep reading and get access to the full archive.

Continue reading