def incrementName(nameList, name):
if name not in nameList:<EOL><INDENT>return name<EOL><DEDENT>newName = name + str(<NUM_LIT:1>)<EOL>for n in range(<NUM_LIT:1>, len(nameList) + <NUM_LIT:2>):<EOL><INDENT>found = False<EOL>for b in nameList:<EOL><INDENT>newName = name + str(n)<EOL>if b == newName:<EOL><INDENT>found = True<EOL><DEDENT><DEDENT>if not found:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return newName<EOL>
return a name that is unique in a given nameList through
attaching a number to it

>>> l = []

now we will add 3xfoo 2xbar and one klaus to our list:

>>> l.append( incrementName(l,'foo') )
>>> l.append( incrementName(l,'bar') )
>>> l.append( incrementName(l,'foo') )
>>> l.append( incrementName(l,'foo') )
>>> l.append( incrementName(l,'bar') )
>>> l.append( incrementName(l,'klaus') )

>>> print sorted(l)
['bar', 'bar2', 'foo', 'foo2', 'foo3', 'klaus']