英文:
change values in a dict
问题
{
'0161811ZWA': [
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0161811ZWA-0.jpg',
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0161811ZWA-2.jpg',
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0161811ZWA-3.jpg'
],
'0162121ZWA': [
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0162121ZWA-0.jpg',
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0162121ZWA-2.jpg',
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0162121ZWA-2.jpg',
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0162121ZWA-3.jpg',
'/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/0162121ZWA-3.jpg'
]
}
英文:
I have a dict with a list of image urls for each product_id.
{'0161811ZWA': ['https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-0_3456144.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-2_3456145.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-3_3456146.jpg'],
'0162121ZWA': ['https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-0_3455932.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-2_3455933.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-2__3524387.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-3_3455934.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-3__3524386.jpg']}
With FTP I made an upload to the remote server.
Now I want to make a new dict with for each product_id a list of paths to the remote server (remote_folder = '/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/'). Filenames stay the same.
答案1
得分: 1
image_dict = {
'0161811ZWA': [
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-0_3456144.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-2_3456145.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-3_3456146.jpg'
],
'0162121ZWA': [
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-0_3455932.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-2_3455933.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-2__3524387.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-3_3455934.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-3__3524386.jpg'
]
}
remote_folder = '/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/'
remote_paths_dict = {}
for product_id, urls in image_dict.items():
remote_paths_dict[product_id] = [
remote_folder + url.split('/')[-1] for url in urls
]
print(remote_paths_dict)
英文:
Simply as:
image_dict = {
'0161811ZWA': [
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-0_3456144.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-2_3456145.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-deauville-0161811-black-3_3456146.jpg'
],
'0162121ZWA': [
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-0_3455932.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-2_3455933.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-2__3524387.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-3_3455934.jpg',
'https://media.lingeriestyling.com/eservices/primadonna-lingerie-underwired_bra-madison-0162121-black-3__3524386.jpg'
]
}
remote_folder = '/httpdocs/PRODUCT_IMAGES/VDV/RESIZED/'
remote_paths_dict = {}
for product_id, urls in image_dict.items():
remote_paths_dict[product_id] = [
remote_folder + url.split('/')[-1] for url in urls
]
print(remote_paths_dict)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论