This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |