Python / Core Python Fundamentals Interview Questions
Which Python built-in functions are most important to know for coding interviews?
Python's built-in namespace contains roughly 70 functions. The ones that come up constantly in interview problems and real-world code are:
Sequence and iteration: len(), range(), enumerate(), zip(), sorted(), reversed(), min()/max() (accept a key= argument), sum(), map(), filter(), any(), all().
Type conversion: int(), float(), str(), bool(), list(), tuple(), set(), dict().
Object introspection: type(), isinstance(), issubclass(), dir(), vars(), hasattr(), getattr(), setattr().
nums = [3, 1, 4, 1, 5, 9, 2, 6] print(sorted(nums)) # [1, 1, 2, 3, 4, 5, 6, 9] print(sorted(nums, reverse=True)) # [9, 6, 5, 4, 3, 2, 1, 1] words = ['banana', 'apple', 'cherry'] print(sorted(words, key=len)) # ['apple', 'banana', 'cherry'] print(any(x > 8 for x in nums)) # True (9 > 8) print(all(x > 0 for x in nums)) # True (all positive) # zip â pair two lists keys = ['a', 'b', 'c'] values = [1, 2, 3 ] print(dict(zip(keys, values))) # {'a':1,'b':2,'c':3}
isinstance(obj, (int, float)) is the right way to check types — it handles subclasses correctly unlike type(obj) == int. For finding the max by a custom criterion: max(employees, key=lambda e: e['salary']).
More Related questions...