Pastebin
Retrouvez, créez et partagez vos snippets en temps réel.
Rechercher un Pastebin
Aucun paste trouvé.
Créer un paste
Pastebin
Blog
randomizing-paintings
import random def randomize_paintings(paintings): """ paintings: list of tuples (orientation, tags) orientation = 'L' or 'P' tags = list of strings Returns: A randomly shuffled list of frameglasses. """ landscapes = [] # frameglasses with 1 landscape painting portraits = [] # list of portrait IDs (to pair later) # Step 1 — Separate portraits and landscapes for pid, (orientation, tags) in enumerate(paintings): if orientation == 'L': landscapes.append([pid]) # one landscape = one frameglass else: portraits.append(pid) # save portrait ID to pair later # Step 2 — Pair portraits (2 by 2) portrait_frames = [] for i in range(0, len(portraits) - 1, 2): portrait_frames.append([portraits[i], portraits[i+1]]) # Step 3 — All frameglasses together frameglasses = landscapes + portrait_frames # Step 4 — RANDOMIZE (shuffle the order) random.shuffle(frameglasses) return frameglasses
Créé il y a 1 mois.