0

I want to get a sublist (not necessarily contigous) with all of the repeated elements from some list. But to clarify things, I don't want just the repeated items, I want them in the same order and quantity they appear in the list. That is:

Input sample:

A = [1, 2, 2, 2, 3, 4, 8, 8, 9, 9]

Expected output:

A = [2, 2, 2, 8, 8, 8, 9, 9]

Does anyone know a good way of doing this?

Mr. T
  • 11,960
  • 10
  • 32
  • 54
Mateus Buarque
  • 255
  • 1
  • 2
  • 9
  • Are equal elements grouped? In other words, is something like `[1, 2, 1]` a valid input? – Aran-Fey Mar 31 '18 at 15:33
  • they may not be, this input is valid. Another way of stating the problem is "how to get a sublist with all non-repeated elements from the previous list removed" – Mateus Buarque Mar 31 '18 at 15:34
  • 1
    What did you try to solve your wants yourself? Happy Coding. SO is about fixing _your_ Code - not implementing your ideas. Please go over [how to ask](https://stackoverflow.com/help/how-to-ask) and [on-topic](https://stackoverflow.com/help/on-topic) again and if you have questions provide your code as [mvce](https://stackoverflow.com/help/mcve). If you encounter errors, copy and paste the error message verbatim ( word for word) into your question. Avoid using screenshots unless you need to convey layout errors. We can NOT copy and paste your image into our IDEs to fix your code. – Patrick Artner Mar 31 '18 at 15:36
  • what about `[1,2,1,2,3,3,2,1,8]` - what would be the expected outcome? – Patrick Artner Mar 31 '18 at 15:37
  • we're not getting your logic. – Jean-François Fabre Mar 31 '18 at 15:38
  • @PatrickArtner [1, 2, 1, 2, 2, 1] – Mateus Buarque Mar 31 '18 at 15:39

0 Answers0