0% found this document useful (0 votes)
3 views1 page

Python Coding Questions

The document contains a list of Python coding interview questions along with their solutions. Key topics include string manipulation, factorial calculation, palindrome checking, finding duplicates, and sorting algorithms. Additional examples cover character frequency, merging dictionaries, and removing duplicates from lists.

Uploaded by

sonalgehlot264
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Python Coding Questions

The document contains a list of Python coding interview questions along with their solutions. Key topics include string manipulation, factorial calculation, palindrome checking, finding duplicates, and sorting algorithms. Additional examples cover character frequency, merging dictionaries, and removing duplicates from lists.

Uploaded by

sonalgehlot264
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Coding Interview Questions & Solutions

1. Reverse a String
text = "python"
print(text[::-1])

2. Factorial
def factorial(n):
result = 1
for i in range(1, n+1):
result *= i
return result

3. Palindrome
text = "madam"
print("Palindrome" if text == text[::-1] else "Not Palindrome")

4. Find Duplicates
numbers = [1,2,3,2,4,1]
duplicates = list(set([x for x in numbers if [Link](x) > 1]))

5. Largest Number
numbers = [10, 5, 20, 8]
print(max(numbers))

6. Character Frequency
text = "python"
freq = {}
for char in text:
freq[char] = [Link](char, 0) + 1

7. Sort without sort()


numbers = [5,2,9,1]
for i in range(len(numbers)):
for j in range(len(numbers)-1):
if numbers[j] > numbers[j+1]:
numbers[j], numbers[j+1] = numbers[j+1], numbers[j]

8. Second Largest
numbers = [10,20,5,8]
numbers = list(set(numbers))
[Link]()
print(numbers[-2])

9. Merge Dictionaries
d1 = {"a":1}
d2 = {"b":2}
merged = {**d1, **d2}

10. Remove Duplicates


numbers = [1,2,2,3,4]
unique = list(set(numbers))

You might also like