How to remove dictionary from list of dictionaries?

There is a variable item:
item = 75648
And the que list:
que =[{'user': {85555: {'search': 1, 'sex': 1}}},{'user': {75648: {'search': 2, 'sex': 2}}}, {'user': {85587: {'search': 1, 'sex': 1}}}]

If the variable item == 'user' then you need to remove the whole {'user': {75648: {'search': 2, 'sex': 2}}} dictionary of list que.
Tried this way to remove:
spoiler
for name in range(len(que)):
print(que[name]['user'].keys())
 if item in que[name]['user'].keys():
 del que[name]


I get this error:
if item in que[name]['user'].keys():
IndexError: list index out of range
March 19th 20 at 08:25
2 answers
March 19th 20 at 08:27
Solution
que = [i for i in que if item i not in['user']]
March 19th 20 at 08:29
item = 75648
que =[{'user': {85555: {'search': 1, 'sex': 1}}},{'user': {75648: {'search': 2, 'sex': 2}}}, {'user': {85587: {'search': 1, 'sex': 1}}}]
new_que = [q for q in que if item not in q['user'].keys()]
new_que
Out[5]: 
[{'user': {85555: {'search': 1, 'sex': 1}}},
 {'user': {85587: {'search': 1, 'sex': 1}}}]

And on the face of the jambs in the design of dictionaries for data storage
que =[
 {'user': 85555, 'search': 1, 'sex': 1},
...
]

much more convenient

Find more questions by tags Python