cyphesis/rulesets/basic/mind/dictlist.py
Al Riddoch f8b54007ac 2006-01-06 Al Riddoch <alriddoch@zepler.org>
* rulesets/Python_API.cpp: Remove C++ implementation of server.dictlist
	  as its installation was messy, and it serves no purpose being
	  implemented in C++.

	* rulesets/basic/mind/NPCMind.py, rulesets/basic/mind/dictlist.py:
	  Use python dictlist implementation from original Python version
	  of cyphesis.
2006-01-06 21:39:00 +00:00

25 lines
794 B
Python
Executable file

#This file is distributed under the terms of the GNU General Public license.
#Copyright (C) 1999 Aloril (See the file COPYING for details).
#dictionary with list of items, key is items name
def add_value(dict, key, item):
"""add value to list in dictionary using key"""
try:
list=dict[key]
if item not in list:
list.append(item)
except KeyError:
dict[key]=[item]
def remove_value(dict, item, remove_empty_key=1):
"""removes value from dictionary and removes key too if no values
and if remove_empty_key true"""
flag=0
for (key,value) in dict.items():
if item in value:
flag=1
value.remove(item)
if remove_empty_key and len(value)==0:
del dict[key]
return flag