I studied that lamda function can be used immediately and discarded where it is needed. What is the relationship between map, filter and lamda?
wins = map(lambda x : 'img' + str(x), range(5))
wins = list(wins)
I studied that lamda function can be used immediately and discarded where it is needed. What is the relationship between map, filter and lamda?
wins = map(lambda x : 'img' + str(x), range(5))
wins = list(wins)
lambda
is often used when there is a better/more efficient solution. While there are places to use lambda
this isn't the most efficient or pythonic solution.
I'd suggest a list comprehension here as it's more readable and efficient for what you're doing.
>>> wins = [f'img{n}' for n in range(5)]
>>> wins
['img0', 'img1', 'img2', 'img3', 'img4']
If your version of python doesn't support f-strings
use str.format
wins = ['img{}'.format(n) for n in range(5)]
Or if you want to use map
then str.format
works here too:
wins = list(map('img{}'.format, range(5)))