在 Python 中,我们有时需要构建一个字典,其中每个键的值都是一个字典。然而,在使用常规字典时,可能会遇到键值被覆盖的问题。例如,以下代码演示了如何使用常规字典构建嵌套字典:
dict_features = {
}
def regexp_features(fileids):
for fileid in fileids:
if re.search(r'мерзавец|подлец', agit_corpus.raw(fileid)):
dict_features[fileid] = {
'oskorblenie':'1'}
else:
dict_features[fileid] = {
'oskorblenie':'0'}
if re.search(