furas

przykład na facebook

Apr 11th, 2020
316
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. flashcards = [
  2.     {
  3.         "id": 1,
  4.         "pytanie": "cokolwiek",
  5.         "back_side": {
  6.             "answer": "NIe wiem",
  7.             "code": ""
  8.         }
  9.     },
  10.     {
  11.         "id": 2,
  12.         "pytanie": "ahahahha",
  13.         "back_side": {
  14.             "answer": "NIe wiem",
  15.             "code": ""
  16.         }
  17.     },
  18.     {
  19.         "id": 3,
  20.         "pytanie": "lblblbbl",
  21.         "back_side": {
  22.             "answer": "sdkfjsdkjfskd",
  23.             "code": ""
  24.         }
  25.     },
  26. ]
  27.  
  28. packages = [
  29.     {"first_packages": [1, 3]},
  30.     {"second_packages": [2, 3]},
  31. ]
  32.  
  33. def get_packages():
  34.     all_packages = list()
  35.    
  36.     for pack in packages:
  37.         for key, values in pack.items():
  38.             # tworzenie nowego pakietu - np. {"first_packages": []}
  39.             data = {key: []}
  40.             for number in values:
  41.                 for card in flashcards:
  42.                     if card['id'] == number:
  43.                         data[key].append(card)
  44.             all_packages.append(data)        
  45.  
  46.     return all_packages
  47.  
  48. get_packages()
  49.  
  50. #-----------------------------------------------------------------------------------
  51.  
  52. Wynik
  53.  
  54. [{'first_packages': [{'back_side': {'answer': 'NIe wiem', 'code': ''},
  55.                       'id': 1,
  56.                       'pytanie': 'cokolwiek'},
  57.                      {'back_side': {'answer': 'sdkfjsdkjfskd', 'code': ''},
  58.                       'id': 3,
  59.                       'pytanie': 'lblblbbl'}]},
  60.  {'second_packages': [{'back_side': {'answer': 'NIe wiem', 'code': ''},
  61.                        'id': 2,
  62.                        'pytanie': 'ahahahha'},
  63.                       {'back_side': {'answer': 'sdkfjsdkjfskd', 'code': ''},
  64.                        'id': 3,
  65.                        'pytanie': 'lblblbbl'}]}]
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×