Hi,
I have a duplicate numbers in a list.I would like to have unique numbers in the list .
Say
Input : - Sample
-
-
l = [ 10,20,30,40,50,10,40,60,70,20]
-
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
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 : - Sample
-
-
l = [ 10,20,30,40,50,10,40,60,70,20]
-
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
- >>> l = [ 10,20,30,40,50,10,40,60,70,20]
-
>>> set(l)
-
set([70, 40, 10, 50, 20, 60, 30])
-
>>> sorted(list(set(l)))
-
[10, 20, 30, 40, 50, 60, 70]
-
>>> [i for i in l if i not in locals()['_[1]']]
-
[10, 20, 30, 40, 50, 60, 70]
-
>>> sorted(dict.fromkeys(l,'?').keys())
-
[10, 20, 30, 40, 50, 60, 70]
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
...
|
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...
|
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...
|
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...
|
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...
|
by: Manish |
last post by:
The topic is related to MySQL database.
Suppose a table "address" contains the following records
-------------------------------------------------------
| name | address | phone |...
|
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...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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,...
| |