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
This is probably the most straightforward way to do it, and also efficient even if
routeshas many items in it:Example usage (using numbers, but this will work for hashable type, e.g. strings are fine):