Search⌘ K
AI Features

Functions and Tricks

Discover advanced functions in Python such as map, filter, sorted, zip, and enumerate. Learn practical tricks like file sharing, variable swapping, and dictionary merging to improve your coding skills and understand Python's versatile features.

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 the k iterables.

Python 3.5
# 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​. ...