change values in a dict

45 views Asked by At

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

There are 1 answers

0
Norhther On

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)