Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing a dictionary from a nested dictionary [duplicate]

I wanna remove a dictionary from a nested dictionary and I don't know how. From this dictionary:

dict = {  
    'user': [
        {
            'firstName': 'john',
            'lastName': 'doe',
            'movieList': []
        },
        {
            'firstName': 'sarah',
            'lastName': 'doe',
            'movieList': []
        },
        {
            'firstName': 'john',
            'lastName': 'smith',
            'movieList': []
        },
        {
            'firstName': 'sarah',
            'lastName': 'smith',
            'movieList': []
        }
    ], 'movie': []
}

I want to remove:

{
    'firstName': 'john', 
    'lastName': 'doe', 
    'movieList': []
}

which has the index 0 I tried using delete but i get this error:

dict['user'][userId] TypeError: list indices must be integers or slices, not str
like image 466
Gallo Avatar asked Dec 06 '25 01:12

Gallo


1 Answers

First, I wouldn't name the dict "dict", use "d" or something else.

dict['user'].pop(0)
like image 63
SuperStew Avatar answered Dec 07 '25 15:12

SuperStew