更改字典中的数值

huangapple go评论55阅读模式
英文:

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)

huangapple
  • 本文由 发表于 2023年7月12日 21:22:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671070.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定