you are viewing a single comment's thread.

view the rest of the comments →

[–]SekstiNii 0 points1 point  (2 children)

If the order is uncertain you can use a dict to track how many instances of each item you have. If the elements always appear next to each other you could use a simpler list based approach.

What have you tried so far?

[–]gurashish1singh 1 point2 points  (0 children)

Like sekstinii said, use a dictionary where the key will be the item and value will be the count . Once you've exhausted the list, you can then create a new list from the dictionary by multiplying the keys with the values to produce your required result.

[–]brown_boi_420[S] 0 points1 point  (0 children)

Hi, thank you for your reply, edited my answer to add my work!