Python Forum

Full Version: How do I change this code for searching duplicats in python ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is the code that I use for searching duplicates in my excel sheet :

def check_duplicacy(first_col):
    first_col_list = first_col.tolist()
    aux_first_col = []
    for i in range(len(first_col_list)):
        if not(pd.isnull(first_col_list[i])):
            if(first_col_list[i] in aux_first_col):
                print('Duplicate found in row nunmber:'+ str(first_col_list[i]))
                return first_col_list[i]
            else:
                aux_first_col.append(first_col_list[i])
    print("No duplicacy found")
    return ""
The code works fine just when I have long list of duplicates it runs for ever. How can I change that the moment find an error stops from the loop.?

Best regards,
Eidrizi