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)
- Create a list of first 10 natural numbers.
- Find the length of a list.
- Access the third element of a list.
- Slice a list from index 2 to 5.
- Append an element to a list.
- Insert an element at index 2.
- Remove an element by value.
- Remove an element by index.
- Reverse a list using slicing.
- Sort a list of integers.
- Create a tuple of 5 fruits.
- Access the last element of a tuple.
- Check if an element exists in a list.
- Count the number of times 5 appears in a list.
- Convert a tuple to a list.
- Convert a list to a tuple.
- Create an empty list and empty tuple.
- Join two lists.
- Join two tuples.
- Find the index of an element in a list.
🧩 Intermediate (Logic + Built-in functions)
- Remove duplicates from a list.
- Find the maximum and minimum in a list.
- Create a list from 1 to 100 using list comprehension.
- Filter even numbers from a list.
- Filter numbers divisible by 3 or 5.
- Square all elements using list comprehension.
- Create a list of tuples with numbers and their squares.
- Flatten a 2D list into a 1D list.
- Zip two lists into a list of tuples.
- Unzip a list of tuples into two lists.
- Rotate a list left by 2 positions.
- Find the second largest number in a list.
- Find the third smallest number in a list.
- Remove all falsy values from a list (
None
,0
,''
, etc.) - Split a list into chunks of size 3.
- Find the most frequent element in a list.
- Check if all elements in list are unique.
- Replace all occurrences of a value with another.
- Count occurrences of each element in a list.
- Merge two sorted lists into one sorted list.
💡 Problem Solving (Application)
- Check if a list is a palindrome.
- Reverse a tuple.
- Find all pairs in list whose sum equals a given value.
- Find common elements in two lists.
- Find elements present in one list but not in another.
- Remove all even indexed elements from a list.
- Create a frequency dictionary from list.
- Group words by their first letter from a list of strings.
- Sort a list of tuples by second element.
- Remove empty strings from a list.
- Find difference between max and min in list of tuples.
- Group a list into sublists of N elements.
- Find duplicates and return only once.
- Replace first and last element in list.
- Swap every pair of elements in a list.
- Convert a list of strings to list of ints.
- Remove negative numbers from list.
- Replace negative numbers with 0.
- Convert list of tuples to dictionary.
- Split list based on a condition.
🧠 Advanced Logic / Tricky
- Find longest increasing subsequence in a list.
- Find the intersection of multiple lists.
- Find the union of multiple lists.
- Check if two lists are anagrams.
- Sort list of tuples based on sum of tuple elements.
- Sort a list of tuples by custom key (e.g., last char of first element).
- Write a function to flatten a deeply nested list.
- Generate all permutations of a list.
- Generate all combinations of a list of length k.
- Implement custom sort using lambda.
- Find element which appears exactly once (others appear twice).
- Rotate list in place (without using extra space).
- Replace every element with the next greatest element.
- Partition a list into even and odd numbers.
- Find product of all elements except current index.
- Rearrange list so that positive and negative alternate.
- Find contiguous subarray with maximum sum (Kadane’s algorithm).
- Merge k sorted lists into one.
- Count triplets in list that sum to 0.
- Find all subsets of a list.
🧪 Tuple Specific Logic
- Find length of longest tuple in list of tuples.
- Check if all tuples in a list are of equal length.
- Count tuples where first and last element are same.
- Sort list of tuples by first element.
- Sort list of tuples by second element descending.
- Create a tuple of squares from 1 to 10.
- Check if a tuple is nested.
- Find common elements in list of tuples.
- Convert a list of strings to list of character tuples.
- Access nested tuple values.
🔐 Pattern-based Challenges
- Return all elements before a specific element in list.
- Check if list contains three consecutive even numbers.
- Find longest sublist without repeating elements.
- Remove K consecutive duplicate elements from a list.
- Implement a stack using list.
- Implement a queue using list.
- Count how many times a pattern appears in list.
- Find the index of first duplicate.
- Find the last non-zero number in list.
- 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
- Sum of all elements in a list
Tag: List, Loop
nums = [1, 2, 3, 4]
print(sum(nums))
- Find the largest number in a list
Tag: List, max
nums = [4, 7, 2]
print(max(nums))
- Check if a list is empty
Tag: List, Condition
lst = []
print("Empty" if not lst else "Not Empty")
- Count occurrences of an element in list
Tag: List, count
lst = [1, 2, 2, 3]
print(lst.count(2))
- Check if all elements are even
Tag: List, all, lambda
lst = [2, 4, 6]
print(all(x % 2 == 0 for x in lst))
- Get unique elements from a list
Tag: Set, List
lst = [1, 2, 2, 3]
print(list(set(lst)))
- 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)
- Merge two lists
Tag: List, Merge
a = [1, 2]
b = [3, 4]
print(a + b)
- Find common elements
Tag: Set, List
a = [1, 2, 3]
b = [2, 3, 4]
print(list(set(a) & set(b)))
- Reverse a list
Tag: List, Slicing
lst = [1, 2, 3]
print(lst[::-1])
🔹 INTERMEDIATE LEVEL
- Rotate list left by k places
Tag: List, Slicing
lst = [1, 2, 3, 4]
k = 2
print(lst[k:] + lst[:k])
- Find second largest number
Tag: List, Sorting
lst = [3, 5, 2, 9]
print(sorted(set(lst))[-2])
- 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)
- 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)
- List of cumulative sums
Tag: List, Accumulator
from itertools import accumulate
lst = [1, 2, 3]
print(list(accumulate(lst)))
- 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])
- Convert list to dictionary (index as key)
Tag: List, Dict
lst = ['a', 'b', 'c']
print({i: val for i, val in enumerate(lst)})
- 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)])
- Check if list is palindrome
Tag: List, Palindrome
lst = [1, 2, 1]
print(lst == lst[::-1])
- Replace specific element
Tag: List, Index
lst = [1, 2, 3]
lst[1] = 99
print(lst)
🔹 ADVANCED LEVEL
- 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]))
- Find frequency of all elements
Tag: List, Counter
from collections import Counter
lst = [1, 2, 2, 3]
print(dict(Counter(lst)))
- 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)))
- Cartesian product of two lists
Tag: List, itertools
from itertools import product
a = [1, 2]
b = ['a', 'b']
print(list(product(a, b)))
- 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)])
- 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])
- Tuple unpacking into variables
Tag: Tuple
t = (1, 2, 3)
a, b, c = t
print(a, b, c)
- 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]))
- 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])
- 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)
- 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)
- Create a histogram from list
Tag: Visualization, Dict
lst = [1,1,2,3]
for val in set(lst):
print(f"{val}: {'*' * lst.count(val)}")
- 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)
- Find mode of a list
Tag: Statistics
from statistics import mode
lst = [1,1,2,3]
print(mode(lst))
- 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)))
Leave a Reply