Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Python Coding Interview Questions and Answers

Ques 11. Write a Python function to check if a given year is a leap year.

def is_leap_year(year):

return (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0)

Example:

is_leap_year(2024)  # Output: True

Is it helpful? Add Comment View Comments
 

Ques 12. Implement a function to find the maximum element in a list.

def find_max_element(lst):

return max(lst)

Example:

find_max_element([3, 7, 2, 8, 5])  # Output: 8

Is it helpful? Add Comment View Comments
 

Ques 13. Write a Python program to count the occurrences of each element in a list.

from collections import Counter

def count_occurrences(lst):

  return Counter(lst)

Example:

count_occurrences([1, 2, 1, 3, 2, 4, 1])  # Output: {1: 3, 2: 2, 3: 1, 4: 1}

Is it helpful? Add Comment View Comments
 

Ques 14. Create a function to check if a given string is an anagram of another string.

def is_anagram(str1, str2):

  return sorted(str1) == sorted(str2)

Example:

is_anagram(\'listen\', \'silent\')  # Output: True

Is it helpful? Add Comment View Comments
 

Ques 15. Implement a function to remove duplicates from a list.

def remove_duplicates(lst):

  return list(set(lst))

Example:

remove_duplicates([1, 2, 2, 3, 4, 4, 5])  # Output: [1, 2, 3, 4, 5]

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2025 WithoutBook