0
Who can help me with this?
Hi, I am a beginner, I can't find a way to get this working. Who can explain what I am doing wrong. My intention is to make a def() with this. The code: #x="0AASFHHRNH0009uh88888kl" #remove the items to get this --> "0ASFHRNH09uh8kl" # #an other example: "265449683338503333" --> "265496838503" #an other example: "abcdeefghiij" --> "abcdefghij" #an other example: "12arh44gooojh" --> "12arh4goj" x="0AASFHHRNH0009uh88888kl" a=list(x) b=list(a) for i in range(len(a)): if a[i]==a[i+1]: del b[i+1] print(b) print(a) print(b)
6 ответов
+ 3
If you like you can try this comprehension:
lst = list('0AASFHHRNH0009uh88888kl')
res1 =[]
[res1.append(item) for i, item in enumerate(lst) if i == 0 or item != lst[i -1]]
print(''.join(res1))
print('0ASFHRNH09uh8kl') # for comparison with sample only
+ 1
Yes, I thing I got it! THANKS.
You are a genius!
+ 1
Goodness! That's something to brew on! Thank you very much.
0
Wow, thank you WhyFry. I wouldn't be able to write this myself. It's so short and clear, however i don't understand what's happening. Why y=""