0

When do you actually implement functional programming in Python?

2nd Jun 2020, 8:16 PM
3.14
3.14 - avatar
2 Answers
+ 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.
2nd Jun 2020, 8:22 PM
Leonid Selivanov
Leonid Selivanov - avatar
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.
2nd Jun 2020, 8:45 PM
Ali Abdelhady
Ali Abdelhady - avatar