Skip to content

Instantly share code, notes, and snippets.

View Alexpeain's full-sized avatar

Alex Peain Alexpeain

View GitHub Profile
@Alexpeain
Alexpeain / 23.2. Map
Created May 19, 2021 14:36
23.2. Map
#1.Using map, create a list assigned to the variable greeting_doubled that doubles each element in the list lst
lst = [["hi", "bye"], "hello", "goodbye", [9, 2], 4]
def cat (f):
return [f]
greeting_doubled = map ( cat , lst)
print(greeting_doubled)
greeting_doubled = map(lambda things : 2* things ,lst )
print(greeting_doubled)
#This summer I will be travelling.
#I will go to...
#Italy: Rome
#Greece: Athens
#England: London, Manchester
#France: Paris, Nice, Lyon
#Spain: Madrid, Barcelona, Granada
#Austria: Vienna
# I will probably not even want to come back!
# However, I wonder how I will get by with all the different languages.
#Write code that uses iteration to print out the length of each element of the list stored in str_list.
str_list = ["hello", "", "goodbye", "wonderful", "I love Python"]
for i in str_list :
print(len(i))
For each word in words, add ‘d’ to the end of the word if the word ends in “e” to make it past tense.
Otherwise, add ‘ed’ to make it past tense. Save these past tense words to a list called past_tense.
words = ["adopt", "bake", "beam", "confide", "grill", "plant", "time", "wave", "wish"]
past_tense = 0
for i in words:
if i in ['bake','confide','time','wave']:
past_tense = i + "d"
else: