TGViewer
Python Projects & Free Books Python Projects & Free Books @pythonfreebootcamp Β· 40.7K subscribers
Post #1338 4.74K
βœ… Python Coding Interview Questions πŸπŸ’»

1️⃣ Q: Return the first duplicate in a list.
def first_duplicate(lst):
seen = set()
for x in lst:
if x in seen:
return x
seen.add(x)
return None

print(first_duplicate([3, 1, 3, 4, 2])) # Output: 3

2️⃣ Q: Check whether a number is a palindrome.
def is_pal_num(n):
return str(n) == str(n)[::-1]

print(is_pal_num(121)) # True
print(is_pal_num(123)) # False

3️⃣ Q: Sort a dictionary by values.
def sort_by_value(d):
return dict(sorted(d.items(), key=lambda x: x[1]))

print(sort_by_value({'a': 3, 'b': 1, 'c': 2}))
Output: {'b': 1, 'c': 2, 'a': 3}

4️⃣ Q: Return all prime numbers in a given range.
def primes_upto(n):
primes = []
for num in range(2, n + 1):
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
break
else:
primes.append(num)
return primes

print(primes_upto(10)) # [2, 3, 5, 7]

5️⃣ Q: Convert a list of numbers into a string.
def list_to_string(lst):
return "".join(map(str, lst))

print(list_to_string([1, 2, 3])) # Output: 123

πŸ’¬ Double Tap ❀️ for Part-12
  • πŸ‘ 2
  • πŸ”₯ 2
  • πŸ₯° 2
  • πŸ‘Œ 1
More from @pythonfreebootcamp
  1. Oct 2, 2026Data Analytics A-Z
  2. Sep 25, 2026🎯 GigaChat 3.5 Reasoning: 5 Key Features 1️⃣ Advanced Reasoning: Explores multiple step-b…
  3. Sep 19, 2026Let’s dive into our first mini project using Python: Project 1: Number Guessing Game 🎯 Go…
  4. Sep 14, 2026Learn AI for Free in 2026πŸ‘‡ 1/ Kaggle Learn: https://www.kaggle.com/learn 2/ Anthropic Lea…
  5. Aug 7, 2026Roadmap to become a data analyst 1. Foundation Skills: β€’Strengthen Mathematics: Focus on s…
  6. Jul 31, 2026🐍 Python Roadmap 1️⃣ Basics: πŸ“πŸ“œ Syntax, Variables, Data Types 2️⃣ Control Flow: πŸ”„πŸ€– If…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook β†’Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 β†’