I dont understand whats wrong.

def remove_duplicates(lis):
    for i,j in enumerate(lis):
        if lis[i]!=lis[i+1]:
            print j
    return slit
print  remove_duplicates([4, 5, 5, 4])


append() is a method, calling a method requires parentheses, square brackets is for accessing strings and list by index

the list should remove all duplicates, so for example:


you should get [1,2,3,4,5], so only to check if the next value doesn't match the current value is not enough


but I am sorting the list first, so all the same values will come next to each other


i missed that, clever

still the problem of append()

also, i+1 will also cause problems for the last item in list, given i+1 is then an index error


yes i+1 will access index which are not in the lists scope, I am thinking of a way around it


hey, so I made those changes and I am recieving this error now,

def remove_duplicates(lis):
    for j in lis:
        if count<=len(lis)-1:
            if lis[count]!=lis[count+1]:
                print j
        return slit
print  remove_duplicates([4, 5, 5, 4])


Oops, try again. Your remove_duplicates modifies the list that was passed to it. [4, 5, 5, 4] was modified to [4, 4, 5, 5]. Perhaps you should make a copy first!


I think the problem is lis and lis.sort(). using for j in lis, you provide python the lis, not lis.sort() (and list.sort() also is unsuitable), so that your code will not be right. I think you should replace:

for j in lis:


new_lis = sorted(lis)
for j in new_list:

or no need to have sorted(lis) separately, just straightly input:

for j in sorted(lis):

and more simple, just try mine :smile:

def remove_duplicates(my_list):
    new_list = []
    for i in my_list:
        if i not in new_list:
    return new_list
print(remove_duplicates([4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]))

Hope you can resolve this.


this does not work it flags off the following error:

Traceback (most recent call last):
File "python", line 15, in
File "python", line 6, in remove_duplicates
TypeError: 'NoneType' object is not iterable

Also your code seems super easy, though I'd like to make mine work, despite being more complex, I just need to believe in my logical ability, I hope you understand.


Oops, I know man, I 've made some changes in my upper reply, please consider and solve it by your way:slight_smile:


I noticed, the changes work. I'll probably look at the code tomorrow morning , with fresh eyes. Thank you for your help so far. You'll defiitely be the first to know when I have successfully debugged my code. :slight_smile:


maybe you should make a copy first then? shouldn't be that difficult

why? .sort() is a method specifically for list, manipulating the list directly rather then returning a new list, which is more efficient then a general sorted() function

The trick is to design an efficient program, but now you have progressed so far, you should make your own code work

we could use sorted() to our advantage, given it will make a copy of the list


Hi there,
I think you've made your code more complicated than it needs to be. I was also getting the TypeError:'NoneType' object is not iterable error and it was super frustrating.
I believe this error exists as a consequence of the lis.sort(). In the instructions, it says to NOT modify the input list, which you do by using this function.
Try using the a not in b syntax suggested in the hint section of the exercise. This is the method I used and it turned out well. :slight_smile:


Yes I had thought of a logic before looking at the hint and then post that I just became adamant on making it work. I have relented now and thought of a different logic and that worksfine. :blush: Thanks for the suggestion!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.