Skip to content

Instantly share code, notes, and snippets.

@charles2588
Created June 27, 2016 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charles2588/e5d50712ea39a36ff5dfd12708e56903 to your computer and use it in GitHub Desktop.
Save charles2588/e5d50712ea39a36ff5dfd12708e56903 to your computer and use it in GitHub Desktop.
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