У меня есть список, как показано ниже:
list = ['15206', '15207', '15269', '15370', '15220', '16224']
Мне нужно удалить повторяющиеся части каждого значения на основе первого:
['15206', '07', '69', '370', '20', '6224']
Кто-нибудь знает, как я могу это сделать этот? Я использую Python.
Это фактический код:
lcod = ['15206', '15207', '15269', '15370', '15220', '16224']
poped = {} # this dict store the number of letters removed in each code
# Each iteration removes 1 letter
for i in range(10):
for seq, cod in enumerate(lcod):
poped[seq] = 0
if seq >= 1:
for seqLetter, letter in enumerate(cod):
# the "seqLetter <= 3" means that it only can remove 3 letters of each code
if letter == lcod[0][seqLetter-poped[seq]] and seqLetter <= 3:
lcod[seq] = cod[1:]
poped[seq] += 1
print(lcod)
возвращает ['15206', '5207', '5269', '370', '220', '224']