list=[]
dict={}
key=sq{}.format(moji)
list.append(su)
dict[key] = list
{'Ah':['10', '20', 'i':['11', '21']}
I included a list in the dictionary so that
I would like to delete the key 'i'
and ['11', '21']
in the list.
dict[key].pop()
list.pop()
Then 'i'
will be deleted, but
If you create 'i'
with the same key, it becomes : ['11', '31'
and only the last content is deleted
list.Clear()
will delete everything.
'i': ['11', '21']
Could you tell me how to delete only completely?
Thank you for your cooperation.
list or dict exist embedded, so it's better to use a different name
Mapping type---dict as described in
If you want to delete the key, do the following:
If you are unsure if a key exists, you can check it as follows:
if 'i' ind:
deld ['I']
If you want to manage each list of keys, you can do the following:
lst=d['Ah']
lst.append('300')
# or
Forkind:
lst = d[k]
lst.pop()
# Or maybe
fork, lst ind.items():
print(f'key: {k}, list: {lst}')
lst.append('A')
© 2024 OneMinuteCode. All rights reserved.