-
-
Save AnisahTiaraPratiwi/ad3eaaee1d02c4ee245ce60b55a90c28 to your computer and use it in GitHub Desktop.
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)) |
jackengtwistio
commented
Dec 8, 2021
•
def combine_lists(list1, list2):
# Generate a new list containing the elements of list2
# Followed by the elements of list1 in reverse order
return list2 + list1[::-1]
Jamies_list = ["Alice", "Cindy", "Bobby", "Jan", "Peter"]
Drews_list = ["Mike", "Carol", "Greg", "Marcia"]
print(combine_lists(Jamies_list, Drews_list))
# works the same but in one line cuz why not
def combine_lists(list1, list2):
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))
def combine_lists(list1, list2):
[list2.append(list1[j]) for j in range(-1, -(len(list1))-1, -1)]
return list2
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):
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))
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))