Python 3 - The Quirky Starmap Function

preview_player
Показать описание
In this session we'll look at the rather interesting starmap function, from the itertools module.

My beginners Python course:

My functional Python course:

-------------
GET The Pythonistas Notebook as your learning companion!
--------------
--------------
JOIN for in-depth coding videos!
------------
Python 3 is an incredible language for beginners, and in each of these videos I am to bring a simple idea to you in short and easy to digest videos. I will be covering data types, control flow, looping, functions, comprehensions, variables, object orientation and much more.
------------
Have a request? Drop me a message!
Рекомендации по теме
Комментарии
Автор

It is worth mentioning that STARmap name is referring to unpacking operator(*). To show how it works (and where the name starmap came from) we can create 3rd version of results:
def pow2(i):
return pow(*i)

results_v3 = map(pow2, nums)

jmf
Автор

I see no reason to use the starmap function. It all can be done with (the more powerful) list comprehension. Is it not in the contrary to the Zen of Python? ("There should be one - and preferably only one - obvious way to do it.")

list(starmap(perimeter, measurements))

[starmap(lambda name, num: (name + ' ') * num, for name, num in names]

vs:

[perimeter(*x) for x in measurements]

[(lambda name, num: (name + ' ') * num)(*x) for x in names]

hipertracker