Skip to content

Instantly share code, notes, and snippets.

@Bovojon
Created October 12, 2017 20:29
Show Gist options
  • Save Bovojon/c7a78bda90c4c3f29089f9e206e68d3c to your computer and use it in GitHub Desktop.
Save Bovojon/c7a78bda90c4c3f29089f9e206e68d3c to your computer and use it in GitHub Desktop.
Airbnb HackerRank Challenge - Pagination
'''
Jon Abdulloev
'''
def paginate(num, results):
outputResults = sortDecreasing(results)
outputResults, paddingList = makeUnique(outputResults)
remaining = len(outputResults)%num
for i in range(remaining):
outputResults.append(paddingList[i])
while num < len(outputResults):
outputResults.insert(num, '')
num += (num+1)
print(outputResults)
def getScore(itemString):
listOfIndividuals = itemString.split(',')
return listOfIndividuals[2]
def getHost(itemString):
listOfIndividuals = itemString.split(',')
return listOfIndividuals[0]
def notIn(string, outputResults):
stringOneList = string.split(',')
for strings in outputResults:
stringTwoList = strings.split(',')
if stringOneList[0] == stringTwoList[0]:
return True
else:
return False
def makeUnique(results):
outputResults = []
paddingList = []
i = 0
while i < (len(results)-1):
if getHost(results[i]) != getHost(results[i+1]):
outputResults.append(results[i])
else:
if notIn(results[i], outputResults):
outputResults.append(results[i])
paddingList.append(results[i+1])
i+=1
if getHost(results[len(results)-1]) != getHost(results[len(results)-2]):
outputResults.append(results[len(results)-1])
return outputResults, paddingList
def sortDecreasing(outputResults):
outputResultsList = []
listOfTuples = []
for item in outputResults:
tupleItem = (int(getHost(item)), item)
listOfTuples.append(tupleItem)
tuples = sorted(listOfTuples, reverse=True)
for i in tuples:
outputResultsList.append(i[1])
return outputResultsList
if __name__ == "__main__":
num = 2
results = [
"2, a, 300.6, SF",
"5, b, 200.1, SF",
"5, c, 900, SF",
"3, e, 100.4, SF",
"7, f, 923.2, SF",
"9, g, 234.1, SF",
"7, h, 201.3, SF",
"7, j, 231.3, SF",
"8, v, 22.2, SF",
"8, v, 22.3, SF",
"8, v, 27.3, SF",
]
paginate(num, results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment