0
When do you actually implement functional programming in Python?
2 odpowiedzi
+ 2
A function is just a way to avoid repeating the same code many times. They are used always and everywhere. DRY - don't repeat yourself.
0
It's a programming style, you decide whether to use it or not, knowing it and knowing when to use it is definitely good
Here is an example
nums = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
nums = [i for i in nums if i % 2 == 0]
nums = filter(lambda x: x % 2 == 0, nums)
They both give the same results, just different styles, in more complex tasks, if you have a function that would get the job done and the list comprehension might be unreadable or complicated then filter might be a better choice.