This file contains hidden or 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
def email_list(domains): | |
emails = [] | |
for domain, users in domains.items(): | |
for user in users: | |
emails.append("{}@{}".format(user, domain)) | |
return(emails) | |
print(email_list({"gmail.com": ["clark.kent", "diana.prince", "peter.parker"], "yahoo.com": ["barbara.gordon", "jean.grey"], "hotmail.com": ["bruce.wayne"]})) |
This file contains hidden or 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
wardrobe = {"shirt":["red","blue","white"], "jeans":["blue","black"]} | |
for item, colors in wardrobe.items(): | |
for color in colors: | |
print("{} {}".format(color, item)) |
This file contains hidden or 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
def count_letters(text): | |
result = {} | |
for letter in text: | |
if letter not in letter: | |
result[letter] = 0 | |
result[letter] += 1 | |
return result |
This file contains hidden or 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
cool_beasts = {"octopuses":"tentacles", "dolphins":"fins", "rhinos":"horns"} | |
for animal, thing in cool_beasts.items(): | |
print("{} have {}".format(animal, thing)) |
This file contains hidden or 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
toc = {"Introduction":1, "Chapter 1":4, "Chapter 2":11, "Chapter 3":25, "Chapter 4":30} | |
toc["Epilogue"] = 39 | |
toc["Chapter 3"] = 24 | |
print(toc) | |
print("Chapter 5" in toc) | |
___ # Epilogue starts on page 39 | |
___ # Chapter 3 now starts on page 24 | |
___ # What are the current contents of the dictionary? | |
___ # Is there a Chapter 5? |
This file contains hidden or 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
def guest_list(guests): | |
for name, age, job in guests: | |
print("{} is {} years old and works as {}".format(name, age, job)) | |
guest_list([('Ken', 30, "Chef"), ("Pat", 35, 'Lawyer'), ('Amanda', 25, "Engineer")]) | |
#Click Run to submit code | |
""" | |
Output should match: | |
Ken is 30 years old and works as Chef |
This file contains hidden or 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
def group_list(group, users): | |
members =", ".join(users) | |
return "{}: {}".format(group, members) | |
print(group_list("Marketing", ["Mike", "Karen", "Jake", "Tasha"])) # Should be "Marketing: Mike, Karen, Jake, Tasha" | |
print(group_list("Engineering", ["Kim", "Jay", "Tom"])) # Should be "Engineering: Kim, Jay, Tom" | |
print(group_list("Users", "")) # Should be "Users:" |
This file contains hidden or 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
def octal_to_string(octal): | |
result = "" | |
value_letters = [(4,"r"),(2,"w"),(1,"x")] | |
# Iterate over each of the digits in octal | |
for number in [int(n) for n in str(octal)]: | |
# Check for each of the permissions values | |
for value, letter in value_letters: | |
if number >= value: | |
result += letter | |
number -= value |
This file contains hidden or 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
def pig_latin(text): | |
say = "" | |
# Separate the text into words | |
temp = [] | |
words = text.split() | |
for word in words: | |
# Create the pig latin word and add it to the list | |
word = word[1:] + word[0] + 'ay' | |
temp.append(word) | |
# Turn the list back into a phrase |
This file contains hidden or 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
filenames = ["program.c", "stdio.hpp", "sample.hpp", "a.out", "math.hpp", "hpp.out"] | |
# Generate newfilenames as a list containing the new filenames | |
# using as many lines of code as your chosen method requires. | |
newfilenames= [file.replace('.hpp','.h') for file in filenames] | |
print(newfilenames) | |
# Should be ["program.c", "stdio.h", "sample.h", "a.out", "math.h", "hpp.out"] |