Services
Back

Question:

reversed, filter, map, bin, abs, hex, all, any

How often asked: Rarely

Suggested by: ALittleMoron


Answer:

These functions all perform different actions.

reversed() - reverses a sequence, returning an iterator for traversing the elements in reverse order.

filter() - selects elements from a sequence based on a given condition (a filter function).

map() - applies a function to each element of a sequence and returns the result.

abs() - returns the absolute value (the absolute value of a number). For example, abs(-5) returns 5.

all() - returns True if ALL elements in the passed sequence are true (or if the sequence is empty).

any() - returns True if AT LEAST ONE element in the sequence is true.

bin() - converts an integer to a binary string with the 0b prefix. For example, bin(5) returns 0b101.

hex() — converts an integer to a hexadecimal string with the 0x prefix. For example, hex(255) returns '0xff'.


Interview answer explanation:

This question is a bit general, because often, if they ask about built-in functions, they'll select one or two, or ask, "Which built-in functions do you know?"

For Junior+, knowing all of these functions isn't necessary, as most code only uses filter and map, although this varies greatly depending on the codebase and business objectives.


External resources: