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)

15th Dec 2019, 5:56 PM
Danny Mientjes
+ 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
15th Dec 2019, 8:34 PM
Lothar
+ 1
Yes, I thing I got it! THANKS. You are a genius!
15th Dec 2019, 7:30 PM
Danny Mientjes
+ 1
Goodness! That's something to brew on! Thank you very much.
15th Dec 2019, 9:05 PM
Danny Mientjes
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=""
15th Dec 2019, 7:18 PM
Danny Mientjes