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 9037967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:22:19+00:00 2026-06-16T09:22:19+00:00

Possible Duplicate: Find and list duplicates in Python list I have this script in

  • 0

Possible Duplicate:
Find and list duplicates in Python list

I have this script in Python:

routes = Trayect.objects.extra(where=['point_id IN (10,59)'])

for route in routes:
    print route

I get this response:

6
106
114
110
118
158
210
110
102
105
110
120
195
106

As you note “110” route is repeated 3 times and “106” is repeated 2 times.

How i can do for obtain only the repeated number?

I want only 110 and 106, not others. Just this:

106
110

Im not a native English speaker, and I am learning python. Thanks

***The objects in list are strings

  • 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-16T09:22:21+00:00Added an answer on June 16, 2026 at 9:22 am

    This is probably the most straightforward way to do it, and also efficient even if routes has many items in it:

    from collections import Counter
    
    counts = Counter(routes)
    
    multi_routes = [i for i in counts if counts[i] > 1]
    

    Example usage (using numbers, but this will work for hashable type, e.g. strings are fine):

    >>> from collections import Counter
    >>> c = Counter([1,1,2,3,3,4,5,5,5])
    >>> [i for i in c if c[i] > 1]
    [1, 3, 5]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Python: How to find list intersection? I have two lists of data
Possible Duplicate: Python - Differences between elements of a list I have a list
Possible Duplicate: Find object by id in array of javascript objects So I have
Possible Duplicate: How do you split a list into evenly sized chunks in Python?
Possible Duplicate: How to Count Duplicates in List with LINQ Any idea how do
Possible Duplicates: find whether a loop in a linked list without two pointers How
Possible Duplicate: How to find a list of wireless networks (SSID's) in Java, C#,
Possible Duplicate: JavaScript - populate drop down list with array I have following select
Possible Duplicate: Algorithm to find which number in a list sum up to a
Possible Duplicates: Fastest way to list all primes below N in python Checking if

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.