💾 Archived View for gemlog.blue › users › georgf › 1614689783.gmi captured on 2023-05-24 at 18:59:45. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-04)

-=-=-=-=-=-=-

Rank-O-Mat

Sometimes you might want to rank people or things: your class, vacation destinations, food, US-presidents etc.

Simply use the sort-routine of your favorite programming language. The clue: YOU are acting as the comparison operator. It's a good idea to shuffle the list of items before starting. Otherwise your decisions might get biased by the original order of the list.

Try:

from functools import cmp_to_key
from random import shuffle

def better(x,y):
	print("Who is better? {0} (1) or {1} (2)".format(x,y))
	while True:
		a=input()
		if a=="1":
			r=1
			break
		elif a=="2":
			r=-1
			break
	return r

liste=["Nixon","Ford","Carter","Reagan","Bush","Clinton","W. Bush","Obama","Trump","Biden"]
shuffle(liste)

liste.sort(key=cmp_to_key(better))
print("*** Result (ascending order) ***")
for n in liste:
	print(n)

Who is the first and last in your list?