Is there a short way to call a function twice or more consecutively in python? For example:
do()
do()
do()
maybe like :
3*do()
Is there a short way to call a function twice or more consecutively in python? For example:
do()
do()
do()
maybe like :
3*do()
My two cents:
Three more ways of doing so:
(I) I think using
map
may also be an option, though is requires generation of an additional list withNone
s in some cases and always needs a list of arguments:(II)
itertools
contain functions which can be used used to iterate through other functions as well https://docs.python.org/2/library/itertools.html(III) Using lists of functions was not mentioned so far I think (and it is actually the closest in syntax to the one originally discussed) :
Or as a one liner: