+ 1
Python List Help
I need help understanding list functions. I know that this list = ['AABBCCDDAABB'] new = [] for i in list: if i not in list: new.append(i) print(new) will return ['A', 'B', 'C', 'D'] So how can I return ['A', 'B', 'C', 'D', 'A', 'B']? Basically I need to remove duplicates while retaining the unique order.
7 Respuestas
+ 7
Check it out, man :)
https://code.sololearn.com/cnM4wycNM0pl/?ref=app
+ 7
I think you put it as a list needlessly. It is basically a string to be processed, so there is no point in storing it as a one-element list.
Store it as a string and then the iteration is easy.
Unless, of course, you really need to store it as a one-element list precisely.
+ 7
Plus, my code works for any such case, where you have this one-element list with a string inside and the string can be of different length, the letters can be du-, tri- or multiplicated, no diff.
+ 6
Cool man. Try experimenting a bit and lose the list's brackets, using purely the string itself. In my code there this allows you to remove all lista[0] references which makes the code cleaner.
+ 1
awesome Kuba! Thanks!
0
ok full disclosure lol:
so I also joined a site http://codewars.com to train my skills more. This is a test case and I've tried many methods already and I also return an error while implementing your solution, Kuba, even tho it works on code playground and IDLE. It was still farther along than what I've tried so far tho.
The problem I think lies in that the list is iterable and there are more than one list entries in the test examples. So returning a new list based off of ['AAAABBBCCDAABB'] will error if any other value is given.
this is confusing me
0
no it doesn't specifically need to be a list *I don't think*, it just seemed like that was the way to do it based off of my skill set.
Maybe I am not understanding the test instructions fully. I'll re-read it and double check.