Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # przeróbka do https://pastebin.com/bMqBxaa2
- flashcards = [
- {
- "id": 1,
- "pytanie": "cokolwiek",
- "back_side": {
- "answer": "NIe wiem",
- "code": ""
- }
- },
- {
- "id": 2,
- "pytanie": "ahahahha",
- "back_side": {
- "answer": "NIe wiem",
- "code": ""
- }
- },
- {
- "id": 3,
- "pytanie": "lblblbbl",
- "back_side": {
- "answer": "sdkfjsdkjfskd",
- "code": ""
- }
- },
- ]
- packages = [ # {name: ids}
- {"first_packages": [1, 3]},
- {"second_packages": [2, 3]},
- ]
- # przerobiona wersja
- def get_packages():
- all_packages = list()
- for pack in packages:
- for name, ids in pack.items():
- selected_cards = []
- for number in ids:
- for card in flashcards:
- if card['id'] == number:
- selected_cards.append(card)
- all_packages.append({name: selected_cards})
- return all_packages
- get_packages()
- # przerobiona wersja zamieniona częściowo w list comprehension
- def get_packages():
- all_packages = list()
- for pack in packages:
- for name, ids in pack.items():
- # list comprehension
- selected_cards = [card
- for number in ids
- for card in flashcards
- if card['id'] == number
- ]
- all_packages.append({name: selected_cards})
- return all_packages
- get_packages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement