Python dictionary: Remove all the keys that begins with s
for k in dic.keys():
if k.startswith('s_'):
del dic[k]
* EDIT *
now in python 3 , years after the original answer, keys()
returns a view into the dict so you can't change the dict size.
One of the most elegant solutions is a copy of the keys:
for k in list(dic.keys()):
if k.startswith('s_'):
del dic[k]
This should do it:
for k in dic.keys():
if k.startswith('s_'):
dic.pop(k)