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']).
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
