A few days ago, the American group pen question
Title: Probably asked to enter two sets of numbers, the two sets of values sorted and then output the results
Idea: Enter two sets of numbers, combine two sets of numbers, sort
1List1 = Raw_input ("input some numbers ex 2 7 1:")2List2 = Raw_input ("input some numbers ex 2 7 1:")3 4 #Convert a string into a list5 6list11 = List1.split (" ")7list22 = List2.split (" ")8 9 #merge list, append list22 to list11 trailerTen #You can also use slices to implement append One A list11.extend (list22) - - #sort the list11 the #about List Sort List.sort () The biggest difference from the sorted function is that sorted returns an object and does not change the original list - PrintSorted (list11)
The resulting returned result may have duplicate elements, so the Deduplication method
1.set Collection because there are no duplicate elements in the collection
1 >>> list = [1,2,3,1,2,3]23 >>> set (list)4 Set ([1, 2, 3])
#注意: Using set does not preserve the original order
2. Iterate through the list, append all elements to the new list if the element is already present in the new list and do not append
1 list = [1,2,1,3,2,]2 list_new = []34 for in list: 5 if not inch list_new: 6 list_new.append (i)7print list_new8
Wait a minute
Simple things to do simply
Python Merge and reorder first