defconcatenate_cmdline_variables(src,names):"""Find duplicate variable declarations on the given source list, and concatenate the values of those in the 'names' list."""# the result list being constructeddest=[]# a map of variable name to destination list indexpositions={}foriteminsrc:i=item.find('=')ifi>0:# it's a variablename=item[:i]ifnameinnames:# it's a known variableifnameinpositions:# already specified: concatenate instead of# appending itdest[positions[name]]+=' '+item[i+1:]continueelse:# not yet seen: append it and remember the list# indexpositions[name]=len(dest)dest.append(item)returndest