Here is my data
pricing = [
{
"link": "https://www.kohls.com/product/prd-3751773/laura-geller-iconic-baked-sculpting-lipstick.jsp?skuid=75792684",
"price": "21",
"stock": true,
"title": "Laura Geller Iconic Baked Sculpting Lipstick, Red Overfl",
"seller": "Kohl's"
},
{
"link": "https://www.macys.com/shop/product/laura-geller-beauty-iconic-baked-sculpting-lipstick-cream?ID=5713197&PartnerID=LINKSHARE&cm_mmc=LINKSHARE-_-4-_-41-_-MP441",
"price": "21.00",
"stock": true,
"title": "Laura Geller Beauty Iconic Baked Sculpting Lipstick - Cream",
"seller": "Macy's"
},
{
"link": "https://www.macys.com/shop/product/laura-geller-beauty-iconic-baked-sculpting-lipstick-cream?ID=5713197&PartnerID=LINKSHARE&cm_mmc=LINKSHARE-_-4-_-41-_-MP441",
"price": "21.00",
"stock": true,
"title": "Laura Geller Beauty Iconic Baked Sculpting Lipstick - Cream",
"seller": "Wal-Mart.com"
}
]
Below code i am writing make them sort as per the list
retailers = ["Amazon", "Wal-Mart.com", "Target", "CVS", "Walgreens","Macy’s", "Nordstrom", "MassGenie", "Kohl's", "Kmart"]
data = sorted(pricing, key=lambda x: retailers.index(x['seller']))
error:
ValueError at /api/product/
"Macy's" is not in list
Here i am trying to sort data by seller key as per the list retailers but, i am getting key error while sorting the data. Please have a look where i am making mistake
I am expecting result:
pricing = [
{
"link": "https://www.macys.com/shop/product/laura-geller-beauty-iconic-baked-sculpting-lipstick-cream?ID=5713197&PartnerID=LINKSHARE&cm_mmc=LINKSHARE-_-4-_-41-_-MP441",
"price": "21.00",
"stock": true,
"title": "Laura Geller Beauty Iconic Baked Sculpting Lipstick - Cream",
"seller": "Wal-Mart.com"
},
{
"link": "https://www.macys.com/shop/product/laura-geller-beauty-iconic-baked-sculpting-lipstick-cream?ID=5713197&PartnerID=LINKSHARE&cm_mmc=LINKSHARE-_-4-_-41-_-MP441",
"price": "21.00",
"stock": true,
"title": "Laura Geller Beauty Iconic Baked Sculpting Lipstick - Cream",
"seller": "Macy's"
},
{
"link": "https://www.kohls.com/product/prd-3751773/laura-geller-iconic-baked-sculpting-lipstick.jsp?skuid=75792684",
"price": "21",
"stock": true,
"title": "Laura Geller Iconic Baked Sculpting Lipstick, Red Overfl",
"seller": "Kohl's"
}
]
Please have a look