Preparing for a Python interview but running short on time? Don’t worry — with the right practice, even 1 hour is enough to boost your confidence. In this guide, we’ll cover 12 Python programs to practice before an interview that focus on the most commonly asked coding challenges. From string manipulation and recursion to lists, dictionaries, and problem-solving, these examples will help you quickly refresh the core concepts. Whether you’re preparing for a software developer role, a data engineer, or a Python-focused interview, these coding exercises will sharpen your skills and get you ready to tackle technical questions.

1. Reverse a String

s = "interview"
print(s[::-1])

2. Check Palindrome

def is_palindrome(s):
    return s == s[::-1]

print(is_palindrome("madam"))
print(is_palindrome("python"))

3. FizzBuzz (Classic)

for i in range(1, 21):
    if i % 3 == 0 and i % 5 == 0:
        print("FizzBuzz")
    elif i % 3 == 0:
        print("Fizz")
    elif i % 5 == 0:
        print("Buzz")
    else:
        print(i)

4. Fibonacci Sequence (first n numbers)

def fibonacci(n):
    a, b = 0, 1
    for _ in range(n):
        print(a, end=" ")
        a, b = b, a + b

fibonacci(10)

5. Factorial (Recursion)

def factorial(n):
    return 1 if n == 0 else n * factorial(n-1)

print(factorial(5))

6. Find Largest Element in List

nums = [10, 34, 56, 7, 89, 23]
print(max(nums))

7. Remove Duplicates from List

nums = [1, 2, 2, 3, 4, 4, 5]
print(list(set(nums)))

8. Count Character Frequency

s = "programming"
freq = {}
for ch in s:
    freq[ch] = freq.get(ch, 0) + 1
print(freq)

9. Anagram Check

def is_anagram(s1, s2):
    return sorted(s1) == sorted(s2)

print(is_anagram("listen", "silent"))
print(is_anagram("hello", "world"))

10. Find Prime Numbers up to n

def primes_upto(n):
    for i in range(2, n+1):
        for j in range(2, int(i**0.5)+1):
            if i % j == 0:
                break
        else:
            print(i, end=" ")

primes_upto(20)

11. Two Sum Problem

nums = [2, 7, 11, 15]
target = 9
seen = {}
for i, num in enumerate(nums):
    if target - num in seen:
        print((seen[target - num], i))
    seen[num] = i

12. Sort Dictionary by Values

d = {"apple": 3, "banana": 1, "cherry": 2}
print(dict(sorted(d.items(), key=lambda x: x[1])))

✅ If you practice these 12, you’ll cover:

  • Strings
  • Lists
  • Dictionaries
  • Loops & conditions
  • Recursion
  • Problem-solving