Jan-18-2017, 07:52 PM
micseydel speaking here: this is a split from https://python-forum.io/Thread-List-show...-instances
Therefore he needs to be shown how to do it correctly so he doesn't think the previous attempt was the best way.
I'm not going to obfuscate a couple lines of code.
Also your suggestion,
Edit: Adding my code to this post so people don't need to link back.
My suggested implementation from the previous thread:
(Jan-18-2017, 07:22 PM)wavic Wrote: [ -> ]I was thinking that this is homeworkYes, except based on his previous post,
Very generously
(Jan-18-2017, 11:00 AM)Pie_Fu n Wrote: [ -> ]ok i've got it sortedhe thinks he has already solved the problem.
if its of benefit to anybody else
Therefore he needs to be shown how to do it correctly so he doesn't think the previous attempt was the best way.
I'm not going to obfuscate a couple lines of code.
Also your suggestion,
wavic Wrote:You need to count an element in the incrementing slices of the first list and append the result for an element to the new list.would be O(n^2) at best.
Edit: Adding my code to this post so people don't need to link back.
My suggested implementation from the previous thread:
sequence = 48,52,55,48,52,55,60,62,48 result = [] cum_count = {} for num in sequence: cum_count[num] = cum_count.get(num, 0) + 1 result.append(cum_count[num]) print(result)
Output:[1, 1, 1, 2, 2, 2, 1, 1, 3]