These are chat archives for Codewars/codewars.com/kata-solving-help

5th
May 2017
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:03

i'm having a tuff time figuring out a kata and google isn't helping me and obviously i cannot see the solution unless i do complete it so you see my problem. i'm working on this Kata (http://www.codewars.com/kata/523f5d21c841566fde000009/train/python)
I cannot seem to remove all the duplicates form the first list, the result im getting is either [1,2,3] or [1,2,2,3]

Jason Pratt
@jasonp26
May 05 2017 22:06
thanks @siebenschlaefer for responding is it ok to paste the code in here?
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:06
yep
but for now I was just looking for a summary in English
like "i copy the input and then delete some entries"
Jason Pratt
@jasonp26
May 05 2017 22:08
ok ill show you a little of the for loop im using
c = []
``````for i in b:
a.remove(i)
for i in a:
if i not in c:
c.append(i)``````
thats the bulk of the code im playing around with but it will not remove all the integers displayed in listB from list A
the lists are formulated like this "array_diff = ([1,2,2,2,3], [2])
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:11
`c` is your result, I guess. So you're modifying a and appending to c?
Jason Pratt
@jasonp26
May 05 2017 22:11
correct
the aim is to strip out ALL the 2's from List A
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:13
I get what you're trying with `for i in b: a.remove(i)`but that only removes the first `i` from a.
Jason Pratt
@jasonp26
May 05 2017 22:13
correct as it iterates on im assuming thus not going back and deleting the other integers?
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:14
I think your approach is rather complicated. Why don't you start from the beginning and formulate a plan. In English.
Jason Pratt
@jasonp26
May 05 2017 22:15
i thought i was making it harder for myself.

i know the plain english of it all would be something along the lines of:

IF the value in ListB appears in List A, remove this value from ListA, copy the remaining into new ListC and print result

as im new to python i am not very sure how to simplify this, too much course material in my head
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:17
then you need a function `remove(array, value)` that removes all elements `value` from `array`.
There is a simple one-line solution, but IMHO it's complicated to get there in one giant step.
Jason Pratt
@jasonp26
May 05 2017 22:18
i think what confuses me a little also about codewars is do i have to use the variables and functions that is shown in the test window?
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:19
The test window is for you. You could even delete everything from it, although that doesn't help at all.
Jason Pratt
@jasonp26
May 05 2017 22:19
ok
ok as a tip so i can focus my attention on that, do you think this could be done with just a IF, Else loop?
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:22
You will need some kind of loop, because you need to inspect each element. (For the listening Python gurus: I said some kind)
Jason Pratt
@jasonp26
May 05 2017 22:23
hehe thanks ok i think i know what i have to try, ill give it a go tomorrow its creeping up to midnight and i have had enough tonight i think. ill just keep practicing it in idle. then come back to codewars afterwards.
thanks @siebenschlaefer for the help and also for pointing out this room for me.
Matthias Rahlf
@siebenschlaefer
May 05 2017 22:23
ok. Good luck and good night.