Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save AnisahTiaraPratiwi/ad3eaaee1d02c4ee245ce60b55a90c28 to your computer and use it in GitHub Desktop.
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 …
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
Copy link

jackengtwistio commented Dec 8, 2021

def combine_lists(list1, list2):

  list1.reverse()
  list2.extend(list1)
  return list2

  
	
Jamies_list = ["Alice", "Cindy", "Bobby", "Jan", "Peter"]
Drews_list = ["Mike", "Carol", "Greg", "Marcia"]

print(combine_lists(Jamies_list, Drews_list))
#works same

@udinnn
Copy link

udinnn commented Dec 26, 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

@cyowmrt
Copy link

cyowmrt commented Jan 23, 2022

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))

@itsaryangupta
Copy link

itsaryangupta commented Feb 25, 2022

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))

@PhoeniX2712
Copy link

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))

@adichamoli14
Copy link

def combine_lists(list1, list2):
combo = [list2]
combo.append(list1[::-1])
return combo

@faithoni
Copy link

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