D=[5,4,2,1,3]
C=["five","four","two","one","three"]
#Combine lists in tuples (5,"five"),(4,"four")...
zipped_lists=zip(D,C)
#Sorts by both values
sorted_pairs=sorted(zipped_lists)
#Unpacks and combines tuples like this (1,2,...) and ("one","two",...)
tuples=zip(*sorted_pairs)
#Lists now sorted
D,C=[list(tuple) for tuple in tuples]
D=[5,4,2,1,3]
C=["five","four","two","one","three"]
#Combine lists in tuples (5,"five"),(4,"four")...
zipped_lists=zip(D,C)
#Sorts by both values
sorted_pairs=sorted(zipped_lists)
#Unpacks and combines tuples like this (1,2,...) and ("one","two",...)
tuples=zip(*sorted_pairs)
#Lists now sorted
D,C=[list(tuple) for tuple in tuples]
var mergeTwoLists = function(list1, list2) {
// using dummy head to avoid writing additional code for edge cases (e.g. list = null).
// using "new" keyword to create a new object. It makes the this variable point to the newly created object.
// p is the pointer of dummy, p1 is the pointer of list1, p2 is the pointer of list2
let dummy = new ListNode(0);
let p = dummy;
let p1 = list1;
let p2 = list2;
// while both lists are not null.
while (p1 && p2 ){
// compare the number of nodes. insert the smaller node to the result
if (p1.val > p2.val){
p.next = p2;
p2 = p2.next;
}else{
p.next = p1;
p1 = p1.next;
}
// move the pointer to the next one
p = p.next;
}
// if every node of one list has been traversaled, we will insert the rest of the other list to the result
p.next = p1 || p2;
return dummy.next;
};
D=[5,4,2,1,3]
C=["five","four","two","one","three"]
#Combine lists in tuples (5,"five"),(4,"four")...
zipped_lists=zip(D,C)
#Sorts by both values
sorted_pairs=sorted(zipped_lists)
#Unpacks and combines tuples like this (1,2,...) and ("one","two",...)
tuples=zip(*sorted_pairs)
#Lists now sorted
D,C=[list(tuple) for tuple in tuples]