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?

6th Apr 2020, 11:04 PM
JGE
JGE - avatar
4 Antworten
+ 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.
8th Apr 2020, 5:10 PM
Lothar
Lothar - avatar
7th Apr 2020, 6:18 AM
Tibor Santa
Tibor Santa - avatar
+ 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.
7th Apr 2020, 2:26 AM
Ahmed Draz
Ahmed Draz - avatar
+ 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
7th Apr 2020, 7:50 AM
visph
visph - avatar