Peeping in.....
A dictionary solution could look like something like this:
data = ['xxx_9999TUNK10_',
'xxx_9999TUNK10_',
'xxx_9999TUNK10_',
'xxx_9999BANK12_',
'xxx_9999BANK17_',
'xxx_9999BANK1_',
'xxx_9999BANK20_',
'xxx_9999BANK20_',
'xxx_9999BANK20_',
'xxx_9999BANK30_' ]
d = {}
cnt = 0
for row in data:
if row not in d.keys():
cnt += 1
d[row] = cnt
print "{}{:04.0f}".format(row, cnt)
else:
print "{}{:04.0f}".format(row, d[row])
'''
Results:
xxx_9999TUNK10_0001
xxx_9999TUNK10_0001
xxx_9999TUNK10_0001
xxx_9999BANK12_0002
xxx_9999BANK17_0003
xxx_9999BANK1_0004
xxx_9999BANK20_0005
xxx_9999BANK20_0005
xxx_9999BANK20_0005
xxx_9999BANK30_0006
'''
Is the prefixed 'xxx_' always the same, or does it vary? If it varies, you will need to do some string splitting, etc.
Is the postfixed '_' always present? If not, the formatting statement can be modified to include it.
By making the dictionary 'd' and the counter 'cnt' global, you should be able to make it work for the field calculator. The code should also work with an update cursor, should you wish to go that route.