devices = [
'SWTEST1-3AA-02',
'SWTEST1-3AA-02',
'SWTEST1-2CA-01',
'SWTEST1-2CA-01',
'SWTEST1-2AA-02',
'SWTEST1-2AA-02',
'SWTEST1-2AA-02'
]
The output that I'm looking for is as follows.
[
'SWTEST1-3AA-02',
'SWTEST1-3AA-02-2',
'SWTEST1-2CA-01',
'SWTEST1-2CA-01-2',
'SWTEST1-2AA-02',
'SWTEST1-2AA-02-2',
'SWTEST1-2AA-02-3'
]
I tried with a for loop and a counter but I'm not getting the results I want, any help will be much appreciated.
For loops that I tried:
counter = 1
out = []
for e in devices:
out.append(f"{e}-{counter}")
counter += 1
print(out)
out = []
d = {}
for i in devices:
counter = 1
d.setdefault(i, -1)
d[i] += 1
if d[i] >= 1:
out.append('{}-{}'.format(i, d[i]))
counter += 1
else:
out.append(i)
print(out)