Exercise #1
'''
EXERCISE #1
Rewrite the following function as a lambda
def string_in(substring, original_str):
return substring in original_str
print(string_in("super","supervisor"))
'''
string_in = lambda substring, original_str: substring in original_str
print(string_in('super', 'supervisor'))
True
Exercise #2
'''
EXERCISE #2
Rewrite the following function as a lambda
It calculates the simple interest on an amount
def interest(amount, rate):
return rate * amount
print('The interest returned is ' + "${:,.2f}".format(interest(125000,.085)))
'''
interest = lambda amount, rate: rate * amount
print('The interest returned is ' + '${:,.2f}'.format(interest(125000, .085)))
The interest returned is $10,625.00
# EXERCISE 3
# code your solution for the email builder here
firstNames = ['Sofia', 'Juan', 'Aria', 'Mohammed', 'Anna', 'Hiroshi',
'Evelyn', 'Lucas', 'Emma', 'Sebastian', 'Lila', 'Elias',
'Yuna', 'Nathan', 'Sophie', 'Nikolai', 'Jasmine', 'Milo',
'Eva', 'Rohan', 'Alessia', 'Max', 'Leila', 'Adam', 'Maya']
emails = []
lambda_func = lambda names: names.lower()
firstNames_lc = map(lambda_func, firstNames)
for n in firstNames_lc:
new_n = n + '@gatordata.com'
emails.append(new_n)
for i in emails:
print(i)
sofia@gatordata.com
juan@gatordata.com
aria@gatordata.com
mohammed@gatordata.com
anna@gatordata.com
hiroshi@gatordata.com
evelyn@gatordata.com
lucas@gatordata.com
emma@gatordata.com
sebastian@gatordata.com
lila@gatordata.com
elias@gatordata.com
yuna@gatordata.com
nathan@gatordata.com
sophie@gatordata.com
nikolai@gatordata.com
jasmine@gatordata.com
milo@gatordata.com
eva@gatordata.com
rohan@gatordata.com
alessia@gatordata.com
max@gatordata.com
leila@gatordata.com
adam@gatordata.com
maya@gatordata.com
Exercise #4 filter
'''
EXERCISE #4
Using the email list that you created, use the filter function to filter out
all email addresses that have the letter "n" in them.
'''
list(filter(lambda e: 'n' not in e, emails))