Created
June 27, 2016 06:02
-
-
Save charles2588/e5d50712ea39a36ff5dfd12708e56903 to your computer and use it in GitHub Desktop.
https://repl.it/C6UJ/0 created by charles2588
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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