I think im over doing it


#1

hi I think I might be over doing this one a tad :smile: but I have been stuck on it for a day not and not really sure how to go about it I have tried for loops but got stuck on how to going over my list again and again to check for doubles. so I set about trying something else but I'm sure there must be a easer way ! any help would be appreciated

def remove_duplicates(orignal_list):

    my_list = orignal_list
    
    total_count = 0
    list_length = 0
    check_value = 0 #list number
    list_value = 0 #list position
    value_repeat = 0 #number of ocerances 

    while True:
        if total_count < (len(my_list) * len(my_list)):
            total_count += 1
            print len(my_list) * len(my_list)
            print total_count
            if list_length <= len(my_list):
                #print "list len",list_length,"my list len", len(my_list)
                list_length += +1
                if my_list[check_value] == my_list[list_value]:
                    #print my_list[check_value], my_list[list_value], "W"
                    value_repeat += +1
                    if value_repeat > 1:
                        #print list_value
                        my_list.remove(list_value)
                        #print "deleting"
                        #print list_value
                        list_value += -1 #move on (dont need this due to going to next number by removing item  
                    else:
                        list_value += +1 #move on to next item
                        #print "hasnt been seen befor, moving on"
                else:
                    list_value += +1 #move on to next item
                    #print "no match, moving on"
                    #print my_list
                    #print list_value, my_list[list_value]
                    #print my_list[check_value], my_list[list_value], "C"
            else:
                check_value += +1
                list_length = 0
                #print "values changed"
        #else:
            #print "ready to return"
            #print my_list

remove_duplicates([1,2,1,3,2])

#2

wow, complicated code. Did you check the hint? It tells you about not in


#3

Would you mind providing the exact link to the exercise you are on.


#4

https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/4


#5

"Overdoing it" might just be the understatement of the year. :wink: Try using this as a template:

def remove_duplicates(PARAMETER):
    LIST_NAME = []
    for INDIVIDUAL ITEMS in LOOPED ITEM:
        if INDIVIDUAL ITEMS not in DIFFERENT ITEM:
            ITEM.append(APPENDED ITEMS)
    return LIST_NAME

However, if and when you get the code to work, make sure you understand why it works. If you have any questions on why it works, please let us know and I'm sure both @stetim94 and myself would be glad to answer them.


#6

haha how simple, maybe I should of looked at the hint ! I must of got side tracked !!! thanks you both for you help. your templates works well and I understand what it is doing. thanks again


#7