In [1]:
l = [1,2,3]
In [20]:
type(l)
Out[20]:
In [19]:
l = {"one":"1","two":"2","Three":3}
l["Three"]
Out[19]:
In [34]:
nums = [3,5,6,10,9,14,14,56,41]
def find_num_greater_than_five(num):
if num > 5:
print("The number {} is greater than 5".format(num))
else:
print("The Number {} is less than or equal to 5".format(num))
In [39]:
number1 = map(find_num_greater_than_five,nums)
for item in number1:
print(item)
In [42]:
number1 = map(find_num_greater_than_five,nums)
for item in number1:
print(item)
In [47]:
def square_num(num):
return num**2
In [48]:
nums = [2,4,6,8]
In [49]:
map(square_num,nums)
Out[49]:
In [50]:
list(map(square_num,nums))
Out[50]:
In [52]:
list(map(lambda num:num**3,nums))
Out[52]:
In [ ]:
people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
def split_title_and_name(person):
return person.split()[0] + ' ' + person.split()[-1]
#option 1
for person in people:
print(split_title_and_name(person) == (lambda person:???))
#option 2
#list(map(split_title_and_name, people)) == list(map(???))
In [53]:
people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
def split_title_and_name(person):
return person.split()[0] + ' ' + person.split()[-1]
map(split_title_and_name,people)
Out[53]:
In [54]:
list(map(split_title_and_name,people))
Out[54]:
In [55]:
people = ['Dr. Christopher Brooks', 'Dr. Kevyn Collins-Thompson', 'Dr. VG Vinod Vydiswaran', 'Dr. Daniel Romero']
#lambda person:person.split()[0] + ' ' + person.split()[-1]
list(map(lambda person:person.split()[0] + ' ' + person.split()[-1],people))
Out[55]:
In [56]:
def times_tables():
lst = []
for i in range(10):
for j in range (10):
lst.append(i*j)
return lst
times_tables()
#times_tables() == [???]
[]
Out[56]:
In [57]:
import googlemaps
from datetime import datetime
gmaps = googlemaps.Client(key='AIzaSyDbkVTmr6r64urBwdPCinoetVAg7nyhVSo')
# Geocoding an address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))
# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
"Parramatta, NSW",
mode="transit",
departure_time=now)
In [63]:
import googlemaps
In [ ]:
gmaps = googlemaps.Client(client_id=client_id, client_secret=client_secret)
# Geocoding and address
geocode_result = gmaps.geocode('1600 Amphitheatre Parkway, Mountain View, CA')
# Look up an address with reverse geocoding
reverse_geocode_result = gmaps.reverse_geocode((40.714224, -73.961452))
# Request directions via public transit
now = datetime.now()
directions_result = gmaps.directions("Sydney Town Hall",
"Parramatta, NSW",
mode="transit",
departure_time=now)