[Python] Create a list of dict key's value as a list from the list of dict [closed]

Discussão em 'Python' iniciado por Stack, Março 9, 2025.

  1. Stack

    Stack Membro Participativo

    Example :

    [[{'name': 'Charan', 'age': 04, 'city': 'bangalore', "Visited Place": "Bhannerghatta Zoo Park"},
    {'name': 'Charan', 'age': 04, 'city': 'bangalore', "Visited Place": "Tunnel Aquarium"},
    {'name': 'Charan', 'age': 04, 'city': 'bangalore', "Visited Place": "Bal Bhavan"}],
    [{'name': 'Pavan', 'age': 17, 'city': 'Hyderabad', "Visited Place": "Charminar"},
    {'name': 'Pavan', 'age': 17, 'city': 'Hyderabad', "Visited place": "Golconda fort"},
    {'name': 'Pavan', 'age': 17, 'city': 'Hyderabad', "Visited Place": "Botanical garden"}],
    [{'name': 'Bharghav', 'age': 07, 'city': 'Vizag', "Visited Place": "Borra Caves"},
    {'name': 'Bharghav', 'age': 07, 'city': 'Vizag', "Visited Place": "Kailasagiri"},
    {'name': 'Bharghav', 'age': 07, 'city': 'Vizag', "Visited Place": "Dolphin's Nose"}]]


    the above sample example contains a list of dictionaries

    Desired output:

    [{'name': 'Charan', 'age': 04, 'city': 'bangalore', "Visited Place": ["Bhannerghatta Zoo Park", "Tunnel Aquarium", "Bal Bhavan"]},
    {'name': 'Pavan', 'age': 17, 'city': 'Hyderabad', "Visited Place": ["Charminar", "Golconda fort", "Botanical garden"]},
    {'name': 'Bharghav', 'age': 07, 'city': 'Vizag', "Visited Place": ["Kailasagiri", "Borra caves", "Kailasagiri"]}]

    Continue reading...

Compartilhe esta Página