Remove successive digits that are duplicate

You are given a number with duplicate digits your task is to remove the immediate duplicate digits and print the result

Input Description:
You are given a long string of digits

Output Description:
Print the desired result print -1 if result length is 0

Sample Input :

Sample Output :

what step comes to your mind as soon as you saw this problem. how to use analytical skills to splve the problem. please explain to me in STEPS how to solve this problem

There’s more than one way to solve this: how would you tackle this project, based on what you know about Python?

i know the basic structure of loops

Okay, well that’s a start, but by itself, it’s not going to cut it.

What about data types?

  • What do you know about string objects?
  • What do you know about list objects?

I ask, because you say that “You are given a long string of digits” which implies that you’re working with a string object, so you’ll need to know what you can and (more importantly) want you can’t do with that object, keeping in mind what the goal of the task is.

edit to add:

Show me what you know about a for loop by posting a code block that iterates over a string object. The object can be what ever you choose. As an example, if your string object = this is a string object, then the for loop should output:

0 : t
1 : h
2 : i
3 : s
4 :  
5 : i
6 : s
7 :  
8 : a
9 :  
10 : s
11 : t
12 : r
13 : i
14 : n
15 : g
16 :  
17 : o
18 : b
19 : j
20 : e
21 : c
22 : t

Post your code block, formatted (using ‘markdown’) like this…

<my code>

… where <my code> is the code block that you’ve constructed.

If you’ve simply no idea where to begin, no worries; I’ll walk you through it – I just need to know what level you’re at.

for i in string object:

Okay, but I know you can do better than that.

Also, I ask again: Post your code block, formatted (using ‘markdown’) like this…

<my code>

… where <my code> is the code block that you’ve constructed.

What string object? You’ve not defined the object.

Have a read of this…

… and try once more to recreate output similar to the output that I posted.

I’m not being deliberately difficult here: what I’m trying to do is to teach you the basic concepts of how the contents of an object can be accessed by referencing an index to said object, which is a concept that you’re going to need, not only to complete your project here, but also, it’s a basic concept that’s used in just about every Python script that I’ve ever written.

I also asked you about data types, which you’ve yet to answer.

Okay. Try it. Does it work? If it doesn’t work, what does it do wrong? How can you fix it?

99% of programming is:

  • Think how to solve the problem first.
  • Write some code to solve it.
  • Run the code and test it. Does it work? If not, write some more code, and test it again.
  • Repeat until the code works.

It will never work perfectly the very first time, unless the problem is trivially simple.

Which means…

If it is not trivial code AND it “works” the first time you run it, you need to look VERY closely at what the program is doing because it is probably failing silently somewhere and giving a wrong result.

< string object = input().split()
for i in string object:
it is very confusing for me. kindly explain the steps


It’s good to see that you are at least trying.

I have to ask this: how is your understanding of English?

The reason I ask, is because you seem to be failing to understand what I’m asking you to do.

I know it must be very hard for you, if you are not only trying to learn a new Programming language, but also trying to learn a new written language.

I’ve been as easy with my English as I know how to be and I really don’t see any way forward here, if you can’t follow what I’m saying.

Explaining Python (which is a technical subject) requires the use of technical language.

I’m trying to understand why you thought that the .split() method would be useful here.

If you want to know how that method could be used, then run this script (below) to see what that method in fact does and think about where you may be able to use that in your future projects: as you move forward, build up a collection of scripts that you can refer to, as and when the need arises.

  • Edit the script by changing the separator (that’s the character between the quotation marks within the .split() method) then again run it, to get a better understanding about what it is doing.
print("This script will split the input at the separator to create a new line.")

text_string = input("Type some text and press Enter: ")
text_list = text_string.split(".")
for word in text_list:

{edit to add}

Thinking about this a little more, I believe I can now see what you are trying to do, based on what little you know about Python.

The script below will (technically and partly) achieve your goal, but in all honesty, it is not how I would encourage you to code, but if it gets you to where you need to be right now, then I suppose it’s as good a starting point as any.

text_list = input("Type 1331 and press enter: ").split("3")

p.s: I am VERY unhappy with this solution and I encourage you to post back and learn how to complete this project in a much better way.

To be clear to any and all readers: there may be some corner case where the above code could be of use, but, generally speaking, DO NOT CODE IN THIS WAY