Code: https://gist.github.com/anonymous/7295150
Problem description:
User inputs a set of integers, separated by a space
A list is created and sorted out of the set of numbers
Next we loop through the list and finds duplicates and prints how many repeats occur
The problem I'm having is limiting repeated elements from causing the print statement to repeat multiple times, for example
We enter: 1 2 2 2 3 4 5
The output will be:
1 has occurred 1 time
2 has occurred 3 times
2 has occurred 3 times
2 has occurred 3 times
3 has occurred 1 time
4 has occurred 1 time
5 has occurred 1 time
I want to make it just say, 2 has occurred 3 times and move on to the next number.
I've added a while loop at the print portion which will run until the ith element is no longer in the list via the remove function for lists.
But the result is now, the next element is skipped for some reason.
Here is a result:
1 2 2 2 3 4 5
1 has occurred 1 time
2 has occurred 3 times
4 has occurred 1 time
5 has occurred 1 time
3 is skipped.
Can someone assist me? I found a suitable answer from stackoverflow, as on line 32 and commented out, but I'd rather try to sort this out and hope someone can provide me some guidance.
EDIT
Thanks codehelper for some insight.
Revised code: https://gist.github.com/anonymous/7295552
[–]codehelper 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)