Une opération courante en python que j’oublie à chaque fois comment faire en one-liner :
1 2 3 4 5 6 |
import random x = [random.randint(1, 100) for _ in range (1000)] # 1000 entiers entre 1 et 100 y = [chr(random.randint(97, 122)) for _ in range (1000)] # 1000 str entre 'a' et 'z' x, y = zip(*sorted(zip(x, y))) # tri par rapport à x x, y = zip(*sorted(zip(x, y), key=lambda el: el[1])) # tri par rapport à y |