Python map() Function

Engr Muhammad Tanveer sultan
2 min readAug 25, 2021

--

Processing Iterables Without a using a Loop (Python)

Transform small case to upper case Letter using Map Function

in Many Programming Language such as JavaScript, Golang etc. map is a higher order Function that applies a given function and iterable the element one by one from the list , array , dict and set etc. the map function get element one by one from the list of dict and set on which the map function apply and send the element to the specified function which is given or pass the first args/parameter of the map.

Syntax of Map Function

syntax of map function
map(any_function, iterables[list,dict,set ect])
Squared value with Map function

Find the Squared of the list element by using map function with lambda

lst = [1,2,3,4,5,6,7,8,9]

squared = map(lambda x:x**2 , lst)

print(list(squared))

output like this

[1, 4, 9, 16, 25, 36, 49, 64, 81]

Square is a Transformation Function that maps the each elements with its square value.

the map() function apply the lambda square function all the element of the iterable list return iterator that yield of square value.

--

--

Engr Muhammad Tanveer sultan

Software Engineer , With hands , on experience in Python | Django | DRF | Flask |Swagger | AWS| ML | Node.js