Python consuming API (Printful)

If you try to print type of test, you will see that it is a dict:

print(type(test)) # dict
print(print(test.keys()) # dict_keys(['code', 'result', 'extra', 'paging'])

Than we need to extract result

print(type(test["result"])) # <class 'list'>
print(len(test["result"])) # 3
print(type(test["result"][0])) # <class 'dict'>

And in this we will extract name from the dict:

print([n for i in test["result"] for k, n in i.items() if k == "name"])

Output:

['Snapback Hat', 'Short-Sleeve Unisex T-Shirt', 'Short-Sleeve Unisex T-Shirt']

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top