ProgramsPython

List Programs

sum, sort, slice, duplicates. Most interview warm-ups are this file.

25 programs · open one, then the next

The matching chapter is Day 5: Lists and List Methods in the Python course. For a short check, try the Python quiz (300 questions). Every topic is listed on Python exercises.

Start with Sum of List Elements
  1. 01Sum of List ElementsBeginnerCalculate the sum of all elements in a list of numbers.Open example →
  2. 02Largest Element in ListBeginnerFind the largest element in a list of numbers.Open example →
  3. 03Smallest Element in ListBeginnerFind the smallest element in a list of numbers.Open example →
  4. 04Count Occurrences in ListBeginnerCount how many times a given element occurs in a list.Open example →
  5. 05Remove Duplicates from ListBeginnerRemove duplicate elements from a list while preserving order.Open example →
  6. 06Merge Two ListsBeginnerMerge two lists into a single list.Open example →
  7. 07Intersection of ListsBeginnerFind the common elements between two lists.Open example →
  8. 08Union of ListsBeginnerFind the union of two lists (unique elements from both).Open example →
  9. 09Sort ListBeginnerSort a list of numbers in ascending order.Open example →
  10. 10Reverse ListBeginnerReverse a list in-place using slicing.Open example →
  11. 11Check if List is SortedBeginnerCheck whether a list is sorted in non-decreasing order.Open example →
  12. 12Find Second Largest ElementBeginnerFind the second largest distinct element in a list.Open example →
  13. 13Find N Largest ElementsBeginnerFind the N largest elements in a list.Open example →
  14. 14Clone / Copy ListBeginneritems[:] and list(items) copy the list, not the name. Change one, the other stays.Open example →
  15. 15Rotate ListBeginnerRotate a list by K positions to the right.Open example →
  16. 16Remove Empty ListsBeginnerRemove empty sublists from a list of lists.Open example →
  17. 17Flatten Nested ListIntermediateFlatten a shallow nested list (list of lists) into a single list.Open example →
  18. 18Find Common Elements of Two ListsBeginnerFind elements that appear in both lists (preserving list order of the first).Open example →
  19. 19List Slicing ProgramsBeginner[:N] prefix, [-N:] suffix, [::K] every Kth. K=0 is a crash, so the code bails.Open example →
  20. 20Replace List ElementsBeginnerReplace all occurrences of a value in a list with another value.Open example →
  21. 21Remove Element by ValueBeginnerRemove the first occurrence of a value from a list, if present.Open example →
  22. 22Count Prime Numbers in ListIntermediateCount how many prime numbers are present in a list of integers.Open example →
  23. 23Pair Sum ProblemIntermediateCheck if there exists a pair of numbers in the list that adds up to a target sum.Open example →
  24. 24Unique Elements from Both ListsIntermediateFind elements that appear in exactly one of the two lists (symmetric difference).Open example →
  25. 25List DifferenceBeginnerFind elements that are in the first list but not in the second.Open example →