我已经用python定义了一个字典
self.cacheDictionary = {}
key = clientname + str(i)
self.cacheDictionary[key] = {'date_populated': str(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")),'date_updated' :str(datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")),'client':clientname,
'site': dirs[i], 'state':'unprocessed', 'machine':'null'}
在上面的运行时中,我构建了密钥。我想在重置缓存时清除缓存中的某些元素。当时,我知道clientname参数。使用它作为正则表达式,我可以在缓存中定位元素吗?所以,我可以很容易地清除它们
我想做的是
self.cacheDictionary[%clientname%].clear()
是和否。你可以通过检查所有的钥匙。但是使用字典的意义在于快速查找,也就是说,不必遍历所有的键,所以从这个意义上说你不能
如果你有选择的话,最好的解决方案是用不同的方式组织你的数据,制作一个有客户名字的字典。在clientnames下面,你放了另一本字典,上面键入了这些被损坏的名字。你把你的原始数据放在下面
示例实现:
如果您的原始字典是固定的,您仍然可以使一个查询字典的关键字客户端名称和值损坏客户端名称
示例实现:
相关问题 更多 >
编程相关推荐