Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
https://repl.it/C6UJ/0 created by charles2588
def SortByExampleArray(exampleArr,testArr):
CountDict=dict((el,0) for el in testArr) #initialize dictionary
Result=[] #initialize empty Result array
for x in testArr:
CountDict[x]+=1 #Store count of each number with it's key
for x in exampleArr:
if x in testArr:
for i in range(CountDict[x]):
Result.append(x)
return Result
testArr=[1,3,7,7,0,4,4,4,4,5,2]
exampleArr=[4,1,2,7,3,5,0]
import datetime
print(datetime.datetime.now().time())
print(SortByExampleArray(exampleArr,testArr))
print(datetime.datetime.now().time())
Python 3.5.1 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
>>> 05:42:30.648760
[4, 4, 4, 4, 1, 2, 7, 7, 3, 5, 0]
05:42:30.648910
=> None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.