Skip to content

Instantly share code, notes, and snippets.

@macloo
Created September 9, 2019 20:14
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 macloo/0c389b0f9fe96f956ad028af585bf9b7 to your computer and use it in GitHub Desktop.
Save macloo/0c389b0f9fe96f956ad028af585bf9b7 to your computer and use it in GitHub Desktop.
Some lists and stuff
percentiles = [10, 20, 30, 40, 50, 60 ,70, 80, 90]
all_scores = [44, 49, 54, 56, 62, 66, 67, 70, 72, 73, 73, 77, 80, 81, 83, 85, 85, 85, 89, 90, 96]
percentiles_with_scores = {k: [] for k in percentiles}
score_percentiles = tuple(zip(np.percentile(all_scores, percentiles), percentiles))
# let's see what's what
print("Tuples:")
print(score_percentiles)
print("The dictionary:")
print(percentiles_with_scores)
for score in all_scores:
for score_percentile, percentile in score_percentiles:
# if score is less than first value in tuple, append to list with key matching second value in tuple
if score <= score_percentile:
percentiles_with_scores[percentile].append(score)
break
print("The result:")
print(percentiles_with_scores)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment