Functions and Tricks
Learn extra tricks and special functions in Python that can help you become more efficient and productive.
Advanced functions
Let’s look at some advanced functions in Python.
Map function
There are two types of map functions:
-
map(func, iter)
:It executes the function on all elements of the iterable.
-
map(func, i1, ..., ik)
:It executes the function on all
k
elements of thek
iterables.
Press + to interact
# map(func, iter)list(map(lambda x: x[0], ['red', 'green', 'blue']))# Result: ['r', 'g', 'b']# map(func, i1, ..., ik)list(map(lambda x, y: str(x) + ' ' + y + 's' , [0, 2, 2], ['apple', 'orange', 'banana']))# Result: ['0 apples', '2 oranges', '2 bananas']
String functions
-
string.join(iter)
:It concatenates iterable elements separated by a string. ...
Access this course and 1400+ top-rated courses and projects.