Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8929463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:40:36+00:00 2026-06-15T08:40:36+00:00

I am fairly new to Python and I am interested in listing duplicates within

  • 0

I am fairly new to Python and I am interested in listing duplicates within a list. I know how to remove the duplicates ( set() ) within a list and how to list the duplicates within a list by using collections.Counter; however, for the project that I am working on this wouldn’t be the most efficient method to use since the run time would be n(n-1)/2 –> O(n^2) and n is anywhere from 5k-50k+ string values.

So, my idea is that since python lists are linked data structures and are assigned to the memory when created that I begin counting duplicates from the very beginning of the creation of the lists.

  1. List is created and the first index value is the word ‘dog’
  2. Second index value is the word ‘cat’
  3. Now, it would check if the second index is equal to the first index, if it is then append to another list called Duplicates.
  4. Third index value is assigned ‘dog’, and the third index would check if it is equal to ‘cat’ then ‘dog’; since it matches the first index, it is appended to Duplicates.
  5. Fourth index is assigned ‘dog’, but it would check the third index only, and not the second and first, because now you can assume that since the third and second are not duplicates that the fourth does not need to check before, and since the third/first are equal, the search stops at the third index.

My project gives me these values and append it to a list, so I would want to implement that above algorithm because I don’t care how many duplicates there are, I just want to know if there are duplicates.

I can’t think of how to write the code, but I figured the basic structure of it, but I might be completely off (using random numgen for easier use):

for x in xrange(0,10):
    list1.append(x)
    for rev, y in enumerate(reversed(list1)):
        while x is not list1(y):
            cond()
            if ???
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:40:37+00:00Added an answer on June 15, 2026 at 8:40 am

    I really don’t think you’ll get better than a collections.Counter for this:

    c = Counter(mylist)
    duplicates = [ x for x,y in c.items() if y > 1 ]
    

    building the Counter should be O(n) (unless you’re using keys which are particularly bad for hashing — But in my experience, you need to try pretty hard to make that happen) and then getting the duplicates list is also O(n) giving you a total complexity of O(2n) == O(n) (for typical uses).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently launching a programme using subprocess.Popen(cmd, shell=TRUE) I'm fairly new to Python, but
I'm fairly new to both Django and Python. This is my first time using
I am fairly new to Python and using Python 3.2. I am trying to
I'm fairly new to python. (Python 2.6) I'm trying to list the running processes
Hello I am fairly new to python and would like to know where my
I'm fairly new to using Python, and I'm trying to get a hit timer
I am fairly new to python, and really new to regex! I am using
I'm fairly new to Python.. I was wondering how do i remove the whitespace
I'm fairly new to Python and have been using Wing IDE to play around
I'm fairly new to Python, so my apologies in advance if this is much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.