I have the following issue : I have been asked to write a python script to list every pair of duplicate names.
The problem is that just a part of the string is similar, the last part is numbers (deployement time), for exemple :
asg-lc-crl-tst-turfpari-rtl20220124153420214800000001
asg-lc-crl-tst-turfpari-rtl20220330150836189100000001
Let's say ; I have a list with this 8 values :
(0) -- asg-lc-crl-tst-turfpari-rtl20220124153420214800000001 <--- duplicate with (1)
(1) -- asg-lc-crl-tst-turfpari-rtl20220330150836189100000001 <--- duplicate with (0)
(2) -- asg-lc-dpr-dev1-app_hode-hdh20220420140650975800000001 <--- duplicate with (4)
(3) -- asg-lc-crl-di1-ledger-manager-rtl20220414144111344500000001
(4) -- asg-lc-dpr-dev1-app_hode-hdh20220420143831109200000001 <--- duplicate with (2)
(5) -- asg-lc-crl-tst-art-manager-rtl20220124162240173500000001 <--- duplicate with (6)
(6) -- asg-lc-crl-tst-art-manager-rtl20220330150933020900000001 <--- duplicate with (5)
(9) -- asg-lc-bck-ope-backoh-oh20201021134525920100000001
(8) -- asg-lc-bck-ope-springbootadmin-oh20201021134526042200000002
I have written this code but it is not working properly :
def list_duplicate_asg(asg1, asg2):
if (asg1.rpartition('-')[0] == asg2.rpartition('-')[0]):
suffix1 = asg1.rpartition('-')[2]
suffix2 = asg2.rpartition('-')[2]
if(suffix1[0:3] == suffix2[0:3]):
print('\n ========== Duplicate exists =========: \n')
print(' + asg1 + ','+ asg2 + '\n ============================ \n')
You see, if the values follow each other in the list, they will be printed like the :
- 0 & 1 : they get printed
- 5 & 6 : they get printed
- But for exemple the (2) & (4) doesn't get printed ...
I dont know if my method of parsing is efficient or if there's one much better ?
And how can I improve my code to be able to detect duplicate even if they're not in order ?
I want the result to be like this :
Duplicats : asg-lc-crl-tst-turfpari-rtl20220124153420214800000001,asg-lc-crl-tst-turfpari-rtl20220330150836189100000001
Duplicats : asg-lc-dpr-dev1-app_hode-hdh20220420140650975800000001,asg-lc-dpr-dev1-app_hode-hdh20220420143831109200000001
Duplicats : asg-lc-crl-tst-art-manager-rtl20220124162240173500000001,asg-lc-crl-tst-art-manager-rtl20220330150933020900000001