# Copyright (c) 2000-2001 LOGILAB S.A. (Paris, FRANCE).
# http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
__revision__ = "$Id: misc.py,v 1.1 2001/12/06 10:45:17 syt Exp $"


##  ###########################################################################
def value(str) :
    if str == 'yes' : return 1
    elif str == 'no' : return 0
    else : return None

def rev_value(num):
    if num == 1 : return 'yes'
    elif num == 0 : return 'no'
    else : return None
    
##  ###########################################################################
def difference(list1, list2):
    """ return elements of list1 not in list2 """
    tmp, l = {}, []
    for i in list2:
        tmp[i]=1
    for i in list1:
        if not tmp.has_key(i):
            l.append(i)
    return l

def intersection(list1, list2):
    """ return common items in list1 and list2 """
    tmp, l = {}, []
    for i in list1:
        tmp[i]=1
    for i in list2:
        if tmp.has_key(i):
            l.append(i)
    return l

def union(list1, list2):
    """ return list1 union list2 """
    tmp = {}
    for i in list1:
        tmp[i]=1
    for i in list2:
        tmp[i]=1
    return tmp.keys()
