def update_tags(self, values, update_type='add'):

        try:
            with self._db_instance:
                if update_type == 'add':
                    self._db_instance.execute('''
                        INSERT or IGNORE into Tags (name, language)
                        VALUES (?, ?)
                    ''', (values['tag_name'], values['language']))

                    self._db_instance.execute('''
                        INSERT or REPLACE into ItemsToTags (tagID, dictID)
                        VALUES (
                        (SELECT id from Tags WHERE name = ? AND language = ?),
                        (SELECT id from Dictionary WHERE problem = ? and language = ?)
                        )''', (values['tag_name'], values['language'], 
                        values['problem'], values['language']))

                #update_type = delete 
                else:
                    self._db_instance.execute('''
                        DELETE from ItemsToTags WHERE dictID = 
                        (SELECT id from Dictionary WHERE problem = ? and language = ?) 
                        AND tagID = (SELECT id from Tags WHERE name = ? AND language = ?)    
                    ''', (values['problem'], values['language'], 
                        values['tag_name'], values['language']))

        except sqlite3.Error as error:
            print "A database error has ocurred: ", error
            sys.exit(1)
Transform expressions into a multinomial form.
dataset/ETHPy150Open BastiPaeltz/codedict/source/database.py/Database.update_tags--crossover with--dataset/ETHPy150Open sympy/sympy/sympy/polys/polyutils.py/parallel_dict_from_expr