SHARE
TWEET

Untitled

a guest Nov 18th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. >>> import random
  2. >>> import string
  3. >>> result = [{'id': i, 'data': d} for i, d in enumerate(string.ascii_uppercase[:15], 1)]
  4. >>> result
  5. [{'id': 1, 'data': 'A'}, {'id': 2, 'data': 'B'}, {'id': 3, 'data': 'C'}, {'id': 4, 'data': 'D'}, {'id': 5, 'data': 'E'}, {'id': 6, 'data': 'F'}, {'id': 7, 'data': 'G'}, {'id': 8, 'data': 'H'}, {'id': 9, 'data': 'I'}, {'id': 10, 'data': 'J'}, {'id': 11, 'data': 'K'}, {'id': 12, 'data': 'L'}, {'id': 13, 'data': 'M'}, {'id': 14, 'data': 'N'}, {'id': 15, 'data': 'O'}]
  6. >>> my_order = list(range(1,16))
  7. >>> my_order
  8. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  9. >>> random.shuffle(my_order)
  10. >>> my_order
  11. [9, 8, 10, 14, 11, 1, 7, 4, 15, 5, 2, 12, 6, 13, 3]
  12. >>> result.sort(key=lambda row: my_order.index(row['id']))
  13. >>> result
  14. [{'id': 9, 'data': 'I'}, {'id': 8, 'data': 'H'}, {'id': 10, 'data': 'J'}, {'id': 14, 'data': 'N'}, {'id': 11, 'data': 'K'}, {'id': 1, 'data': 'A'}, {'id': 7, 'data': 'G'}, {'id': 4, 'data': 'D'}, {'id': 15, 'data': 'O'}, {'id': 5, 'data': 'E'}, {'id': 2, 'data': 'B'}, {'id': 12, 'data': 'L'}, {'id': 6, 'data': 'F'}, {'id': 13, 'data': 'M'}, {'id': 3, 'data': 'C'}]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top