0
Can someone give a real-life situation where map and filters are used?
I understand the theory, but where/when is map or filter used in a real application?
4 odpowiedzi
+ 5
A sample for map() could be:
If an input is taken with comma or space separated multiple numbers, each of the numbers should be converted to int or to float:
lst1 = list(map(int ,input('Enter values sep. by comma: ').split(',')))
If the input is: 24, 2, 0, 54
the result will be a list: [24, 2, 0, 54] of integers.
+ 3
Here is a very simple one.
https://code.sololearn.com/cropwUeWd3NE/?ref=app
+ 2
Map : is used to apply a certain function on each element in iterable. otherwise the Filter : is used to filter out some elements in iterable that do match the certain condition. so for example filter function can be shown in (products price filter),
Map function can be used to change the type of each element in the list(mutable iterable) like "list(map(int, input(). split() ))"
in this example you change all the elements"strings" in the input list to integer values. and there are many applications of both map and filter. I hope this answer help you.
+ 1
in functional programing they are the basics of data handling: everywhere you deal with data list (mostly of the processed data are organized as list)... either as in memory and/or from stream.
https://trivento.nl/three-functional-programming-examples-in-javascript/
https://youtu.be/EzB6Pk66XW8