This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_laptop_not_sugar(payload: dict) -> List: | |
response = [] | |
items = payload.get("items") | |
if items: | |
for item in items: | |
memories = item.get("memory", []) | |
processors = item.get("processor", []) | |
for memory in memories: | |
if memory.get("size") == 16: | |
for processor in processors: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_laptop_sugar_2(payload: dict) -> List: | |
return [i for i in payload.get("items", []) if | |
{"size": 16} in i.get("memory", []) and [j for j in i.get("processor", []) if | |
j.get("make", "").upper() == "RYZEN"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_laptop_sugar_1(payload: dict) -> List: | |
return list(filter(lambda l: | |
list(filter(lambda ll: ll.get("size") == 16, l.get("memory", []))) | |
and | |
list(filter(lambda ll: ll.get("make", "").upper() == "RYZEN", l.get("processor", []))) | |
, | |
payload.get("items", []))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"items": [ | |
{ | |
"make": "acer", | |
"model": "aspire", | |
"screen_size": "17", | |
"memory": [ | |
{ | |
"size": 8 | |
}, |