furas

przykład na facebook

Apr 11th, 2020
282
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # przeróbka do https://pastebin.com/bMqBxaa2
  2.  
  3. flashcards = [
  4.     {
  5.         "id": 1,
  6.         "pytanie": "cokolwiek",
  7.         "back_side": {
  8.             "answer": "NIe wiem",
  9.             "code": ""
  10.         }
  11.     },
  12.     {
  13.         "id": 2,
  14.         "pytanie": "ahahahha",
  15.         "back_side": {
  16.             "answer": "NIe wiem",
  17.             "code": ""
  18.         }
  19.     },
  20.     {
  21.         "id": 3,
  22.         "pytanie": "lblblbbl",
  23.         "back_side": {
  24.             "answer": "sdkfjsdkjfskd",
  25.             "code": ""
  26.         }
  27.     },
  28. ]
  29.  
  30. packages = [ # {name: ids}
  31.     {"first_packages": [1, 3]},
  32.     {"second_packages": [2, 3]},
  33. ]
  34.  
  35. # przerobiona wersja
  36.  
  37. def get_packages():
  38.     all_packages = list()
  39.    
  40.     for pack in packages:
  41.         for name, ids in pack.items():
  42.            
  43.             selected_cards = []
  44.            
  45.             for number in ids:
  46.                 for card in flashcards:
  47.                     if card['id'] == number:
  48.                         selected_cards.append(card)
  49.                        
  50.             all_packages.append({name: selected_cards})        
  51.  
  52.     return all_packages
  53.  
  54. get_packages()
  55.  
  56. # przerobiona wersja zamieniona częściowo w list comprehension
  57.  
  58. def get_packages():
  59.     all_packages = list()
  60.    
  61.     for pack in packages:
  62.         for name, ids in pack.items():
  63.            
  64.             # list comprehension
  65.             selected_cards = [card
  66.                 for number in ids
  67.                     for card in flashcards
  68.                         if card['id'] == number
  69.             ]
  70.                        
  71.             all_packages.append({name: selected_cards})        
  72.  
  73.     return all_packages
  74.  
  75. get_packages()
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.

×