repl.it
@charles2588/

SortByExampleArray

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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())
?