Python - delete multiple list elements in dictionary -
i have simple dictionary structure in python being used pseudo database. example of 6 entries shown below:
a={} a['name'] = ['a','b','c','d','e','f'] a['number'] = [1 ,2 ,3 ,4 ,5 ,6 ] a['sum'] = [2 ,1 ,4 ,3 ,6 ,5 ]
each key in dictionary refers specific field type e.g. name, number, sum etc , data stored against key list of length n, n number of entries. note lists of length n. set allows me access records each entry, example, 3rd entry fields can use:
a['name'][2] a['number'][2] a['sum'][2]
filling structure easy using dictionary append method. question deleting entries. suppose want remove 1 of records leave rest in same dictionary / lists, how do this? mean, how remove third entry such dictionary , lists now:
a['name'] = ['a','b','d','e','f'] a['number'] = [1 ,2 ,4 ,5 ,6 ] a['sum'] = [2 ,1 ,3 ,6 ,5 ]
any appreciated. implemented in loop somewhere in code i.e. i'm looking remove ith entry opposed 3rd entry.
with data structure, there's not better can than
for v in a.values(): del v[2] # or v[n] in general
Comments
Post a Comment