Click here (these are ready-to-use for your projects) Python code- def return_union(list_a, list_b): return sorted(list_a + list_b) R code- return_union <- function(list_a, list_b) { list_c<-list(c(unlist(list_a),unlist(list_b))) return(list(list_c[[1]][order(list_c[[1]])])) } Generally, the tricky part of the question is not to use any sorting or ordering function.
Python code- def return_union(list_a, list_b): len1 = len(list_a) len2 = len(list_b) final_sorted_list = [] j = 0 k = 0 for i in range(len1+len2): if k == len1: final_sorted_list.extend(list_b[j:]) break elif j == len2: final_sorted_list.extend(list_a[k:]) break elif list_a[k] < list_b[j]: final_sorted_list.append(list_a[k]) k += 1 else: final_sorted_list.append(list_b[j]) j += 1 return final_sorted