MAP()
PYTHONCreated By:
Muhammad Fathan M. (1906293190)
Marcia Nadin (1906293146)
Nabila Khansa (1906293221)
Dwi Ayu Sekarini P. (1906399190)
Under Guidance Of
Fariz Darari, S.Kom, M.Sc., Ph.D.
MAP()
FUNCTION
The map function takes two
arguments:
Function
Iterable object
It applies the function to all
items of the iterable object,
returning a map object.
1
2
2
OUTPUT :
<MAP OBJECT>
The map object is an iterator,
with elements able to be
iterated over.
It can also be converted into a
sequence object such as :
List
Tuple
Etc.
1
2
3
3
GIG 4
1
2
Convert all string numbers
to integer inside a list
[‘1’,’2’,’3’,’4’,’5’]
[1,2,3,4,5]
DIRECT METHOD 5
>>>
>>>
>>>
>>>
>>>
str_num = [‘1’,’2’,’3’,’4’,’5’]
int_numbers = [] #create an empty list
for i in str_num: #using for loop
a = int(i) #use the int() function
int_num.append(a) #appends result to a new list
int_num
[1,2,3,4,5]
OUTPUT
MAP() FUNCTION
Data = a1, a2, a3, a4, …
Function: f(x)
map(f, Data):
return an iterator over f(a1),
f(a2), f(a3), f(a4), ...
6
GIG 2 7
given a list of three
dimensional points in the
form of tuples, create a
new list consisting of the
distances of each point
from the origin
MAP() FUNCTION
from math import sqrt
points = [(2,1,3),(5,7,-3),(2,4,0),(9,6,8)]
def distance(point):
x,y,z = point
return sqrt(x**2 + y**2 + z**2)
distances = list(map(distance,points))
8
UTILIZING MAP FUNCTION 9
>>>
>>>
>>>
string_numbers = [‘1’,’2’,’3’,’4’,’5’]
int_numbers = map(int, string_numbers)
int_numbers
<map object at 0x000001C05465E370>
*Map function does not return a list
Converting the Result 10
Convert using the list function
string_numbers = [‘1’,’2’,’3’,’4’,’5’]
int_numbers = list(map(int, string_numbers))
int_numbers
>>>
>>>
>>>
OUTPUT
[1,2,3,4,5]>>>
11
THANKS
CREDITS
• Presentation template by Slidesgo
• Icons by Flaticon
• Infographics by Freepik
• Images created by Freepik- Freepik
• Author introduction slide photo created by
Freepik
• Text & Image slide photo created by
Freepik.com
• Courses.cs.washington.edu

Map()

  • 1.
    MAP() PYTHONCreated By: Muhammad FathanM. (1906293190) Marcia Nadin (1906293146) Nabila Khansa (1906293221) Dwi Ayu Sekarini P. (1906399190) Under Guidance Of Fariz Darari, S.Kom, M.Sc., Ph.D.
  • 2.
    MAP() FUNCTION The map functiontakes two arguments: Function Iterable object It applies the function to all items of the iterable object, returning a map object. 1 2 2
  • 3.
    OUTPUT : <MAP OBJECT> Themap object is an iterator, with elements able to be iterated over. It can also be converted into a sequence object such as : List Tuple Etc. 1 2 3 3
  • 4.
    GIG 4 1 2 Convert allstring numbers to integer inside a list [‘1’,’2’,’3’,’4’,’5’] [1,2,3,4,5]
  • 5.
    DIRECT METHOD 5 >>> >>> >>> >>> >>> str_num= [‘1’,’2’,’3’,’4’,’5’] int_numbers = [] #create an empty list for i in str_num: #using for loop a = int(i) #use the int() function int_num.append(a) #appends result to a new list int_num [1,2,3,4,5] OUTPUT
  • 6.
    MAP() FUNCTION Data =a1, a2, a3, a4, … Function: f(x) map(f, Data): return an iterator over f(a1), f(a2), f(a3), f(a4), ... 6
  • 7.
    GIG 2 7 givena list of three dimensional points in the form of tuples, create a new list consisting of the distances of each point from the origin
  • 8.
    MAP() FUNCTION from mathimport sqrt points = [(2,1,3),(5,7,-3),(2,4,0),(9,6,8)] def distance(point): x,y,z = point return sqrt(x**2 + y**2 + z**2) distances = list(map(distance,points)) 8
  • 9.
    UTILIZING MAP FUNCTION9 >>> >>> >>> string_numbers = [‘1’,’2’,’3’,’4’,’5’] int_numbers = map(int, string_numbers) int_numbers <map object at 0x000001C05465E370> *Map function does not return a list
  • 10.
    Converting the Result10 Convert using the list function string_numbers = [‘1’,’2’,’3’,’4’,’5’] int_numbers = list(map(int, string_numbers)) int_numbers >>> >>> >>> OUTPUT [1,2,3,4,5]>>>
  • 11.
    11 THANKS CREDITS • Presentation templateby Slidesgo • Icons by Flaticon • Infographics by Freepik • Images created by Freepik- Freepik • Author introduction slide photo created by Freepik • Text & Image slide photo created by Freepik.com • Courses.cs.washington.edu