473,387 Members | 1,624 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Deleting duplicate elements in list

440 256MB
Hi,

I have a duplicate numbers in a list.I would like to have unique numbers in the list .

Say
Input :

Expand|Select|Wrap|Line Numbers
  1. Sample
  2.  
  3. l = [ 10,20,30,40,50,10,40,60,70,20]
  4.  
output should be :
'l' should have

l = [ 10,20,30,40,50,60,70].

Is there any method available to remove the duplicate elements in the list?

-PSB
Apr 9 '07 #1
2 3710
bvdet
2,851 Expert Mod 2GB
Hi,

I have a duplicate numbers in a list.I would like to have unique numbers in the list .

Say
Input :

Expand|Select|Wrap|Line Numbers
  1. Sample
  2.  
  3. l = [ 10,20,30,40,50,10,40,60,70,20]
  4.  
output should be :
'l' should have

l = [ 10,20,30,40,50,60,70].

Is there any method available to remove the duplicate elements in the list?

-PSB
Expand|Select|Wrap|Line Numbers
  1. >>> l = [ 10,20,30,40,50,10,40,60,70,20]
  2. >>> set(l)
  3. set([70, 40, 10, 50, 20, 60, 30])
  4. >>> sorted(list(set(l)))
  5. [10, 20, 30, 40, 50, 60, 70]
  6. >>> [i for i in l if i not in locals()['_[1]']]
  7. [10, 20, 30, 40, 50, 60, 70]
  8. >>> sorted(dict.fromkeys(l,'?').keys())
  9. [10, 20, 30, 40, 50, 60, 70]
  10. >>> 
Apr 9 '07 #2
http://www.thescripts.com/forum/thread26978.html

Check the link, that method is very fast.
Apr 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: flupke | last post by:
Hi, i'm having trouble with deleting elements from a list in a for loop ============== test program ============== el = print "**** Start ****" print "List = %s " % el index = 0 for line...
1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
18
by: Dan | last post by:
hello, I would to know if it is possible to delete an instance in an array, The following does not allow me to do a delete. I am trying to find and delete the duplicate in an array, thanks ...
2
by: KraftDiner | last post by:
I have a list, and within it, objects are marked for deletion. However when I iterate through the list to remove objects not all the marked objects are deleted.. here is a code portion: i = 0...
3
by: Nathan Bloom | last post by:
Hi, I have a data entry form (access 2000) that also allows the user to add, update, and delete records from the form. The Delete action is carried out in an event procedure and has the...
4
by: gurvar | last post by:
Hi I'm trying to remove duplicate elements from a Drop Down List Fill in VB.net. Following code worked well with vb6. But I'm getting index out of range if I try to translate it to vb.net code...
25
by: Markus Svilans | last post by:
Hi, There seems to be some functionality missing from the STL. I am iterating through a linked list (std::list) using a reverse iterator and attempting to erase certain items from the list. It...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
7
by: swami | last post by:
What is the query for selecting non duplicate elements for eg: no name age 1 siva 28 2 blair 32 3 mano 28 i want to select blair which hasn't got any duplicate...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.