Last active
June 10, 2022 13:23
-
-
Save LizaPiya/612b61653bbb4776f7e95a67797f689f to your computer and use it in GitHub Desktop.
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 to add ‘Guadalajara’ to the end of the list trav_dest using a list method. | |
trav_dest = ['Beirut', 'Milan', 'Pittsburgh', 'Buenos Aires', 'Nairobi', 'Kathmandu', 'Osaka', 'Melbourne'] | |
trav_dest.append('Guadalajara') |
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 to rearrange the strings in the list winners so that they are in alphabetical order from A to Z | |
winners = ['Kazuo Ishiguro', 'Rainer Weiss', 'Youyou Tu', 'Malala Yousafzai', 'Alice Munro', 'Alvin E. Roth'] | |
for i in winners: | |
winners.sort() |
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 to switch the order of the winners list so that it is now Z to A. Assign this list to the variable z_winners. | |
winners = ['Alice Munro', 'Alvin E. Roth', 'Kazuo Ishiguro', 'Malala Yousafzai', 'Rainer Weiss', 'Youyou Tu'] | |
winners.sort(reverse=True) | |
z_winners = winners |
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 character in the string already saved in the variable str1, add each character to a list called chars. | |
str1 = "I love python" | |
# HINT: what's the accumulator? That should go here. | |
chars=[] | |
for i in str1: | |
chars.append(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
###Assign an empty string to the variable output. Using the range function, write code to make it so that the variable output has 35 a s inside it (like "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"). | |
Hint: use the accumulation pattern! | |
output = "" | |
for i in range(0,35): | |
output = output + 'a' | |
print(output) |
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 string in wrds, add ‘ed’ to the end of the word (to make the word past tense). Save these past tense words to a list called past_wrds. | |
wrds = ["end", 'work', "play", "start", "walk", "look", "open", "rain", "learn", "clean"] | |
check=[] | |
for string in wrds: | |
string=string+"ed" | |
check.append(string) | |
print (check) | |
past_wrds=check |
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 to take ‘London’ out of the list trav_dest. | |
trav_dest = ['Beirut', 'Milan', 'Pittsburgh', 'Buenos Aires', 'Nairobi', 'Kathmandu', 'Osaka', 'London', 'Melbourne'] | |
trav_dest.remove('London') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Team,
colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Indigo", "Violet", "Purple", "Pink", "Brown", "Teal", "Turquois", "Peach", "Beige"]
for position in range(len(colors)):
color = colors[position]
print(color)
if color[0] in ["P", "B", "T"]:
del colors[position]
print(colors)
#can you explain what is doing the renge and the len functions. Thanks