Created
March 23, 2021 23:10
-
-
Save AnisahTiaraPratiwi/ad3eaaee1d02c4ee245ce60b55a90c28 to your computer and use it in GitHub Desktop.
A professor with two assistants, Jamie and Drew, wants an attendance list of the students, in the order that they arrived in the classroom. Drew was the first one to note which students arrived, and then Jamie took over. After the class, they each entered their lists into the computer and emailed them to the professor, who needs to combine them …
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 combine_lists(list1, list2): | |
# Generate a new list containing the elements of list2 | |
# Followed by the elements of list1 in reverse order | |
new_list = list2 | |
for i in reversed(range(len(list1))): | |
new_list.append(list1[i]) | |
return new_list | |
Jamies_list = ["Alice", "Cindy", "Bobby", "Jan", "Peter"] | |
Drews_list = ["Mike", "Carol", "Greg", "Marcia"] | |
print(combine_lists(Jamies_list, Drews_list)) |
def combine_lists(list1, list2):
combo = [list2]
combo.append(list1[::-1])
return combo
def combine_lists(list1, list2):
Generate a new list containing the elements of list2
Followed by the elements of list1 in reverse order
list1.reverse()
return(list2 + list1)
Jamies_list = ["Alice", "Cindy", "Bobby", "Jan", "Peter"]
Drews_list = ["Mike", "Carol", "Greg", "Marcia"]
print(combine_lists(Jamies_list, Drews_list))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def combine_lists(list1, list2):
new_list=list2+list1[::-1]
return new_list
Jamies_list = ["Alice", "Cindy", "Bobby", "Jan", "Peter"]
Drews_list = ["Mike", "Carol", "Greg", "Marcia"]
print(combine_lists(Jamies_list, Drews_list))