我是一个python初学者,我想知道如何删除Python中列表中多次出现的项目。这是我的清单:
["0101013132","0101410142","0101430144"]
我想要做的第一件事是更换所有" 01"通过" 1",第二件事就是取代" 31"," 32" by" 3"分别替换" 41"," 42"," 43"," 44" by" 4"分别
我不知道该怎么做。谢谢!
抱歉混淆。我想要的是将我的列表变成这个: [" 11133"" 11414"" 11414"]
答案 0 :(得分:1)
my_list = ["0101013132","0101410142","0101430144"]
normalized_list = []
for item in my_list:
normalized_list.append(item.replace('01', '1').replace('31', '3').replace('32', '3')) # and so one...)
print(normalized_list)
答案 1 :(得分:1)
L = ["0101013132","0101410142","0101430144"]
answer = [s[::2].replace('0', '1') for s in L]
In [7]: answer
Out[7]: ['11133', '11414', '11414']
答案 2 :(得分:0)
l = ["0101013132","0101410142","0101430144"]
[ ''.join( map( lambda x : str(x)[0] ,map( int, map(''.join, zip( *( [iter(s)]*2) ) ) ) ) ) for s in l ]