Skip to content

Instantly share code, notes, and snippets.

@LizaPiya
Last active June 10, 2022 13:23
Show Gist options
  • Save LizaPiya/612b61653bbb4776f7e95a67797f689f to your computer and use it in GitHub Desktop.
Save LizaPiya/612b61653bbb4776f7e95a67797f689f to your computer and use it in GitHub Desktop.
##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')
##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()
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
##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)
###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)
#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
## 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')
@AdrianMXO
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment