filmov
tv
Python Dictionary Comprehension , Map & Lambda Function.
Показать описание
Like List Comprehension, Python allows dictionary comprehensions. We can create dictionaries using simple expressions.
A dictionary comprehension takes the form
{key: value for (key, value) in iterable}
# dictionary comprehension example
square_dict = {num: num*num for num in range(1, 11)}
print(square_dict)
map() function returns a map object(which is an iterator) of the results after applying the given function to each item of a given iterable (list, tuple etc.)
A lambda function is a small anonymous function.
A lambda function can take any number of arguments, but can only have one expression.
A dictionary comprehension takes the form
{key: value for (key, value) in iterable}
# dictionary comprehension example
square_dict = {num: num*num for num in range(1, 11)}
print(square_dict)
map() function returns a map object(which is an iterator) of the results after applying the given function to each item of a given iterable (list, tuple etc.)
A lambda function is a small anonymous function.
A lambda function can take any number of arguments, but can only have one expression.