Hi,
I have two lists,i have to get the remaining list elements other than common elements.
I/P :
l1 = [1,2,3,4]
l2=[2,3]
O/P
From l1 & l2.I have to get the uncommon elements
[1,4]
Thanks
PSB
3 21010
Hi,
I have two lists,i have to get the remaining list elements other than common elements.
I/P :
l1 = [1,2,3,4]
l2=[2,3]
O/P
From l1 & l2.I have to get the uncommon elements
[1,4]
Thanks
PSB
With sets you can do union, intersection, ect. Or:
>>> l1 = [1, 2, 3, 4]
>>> l2 = [2, 3]
>>> list(set(l1) - set(l2))
[1, 4]
>>>
you should be able to understand how to use sets by now, since barton has showed you how here bvdet 2,851
Expert Mod 2GB
If you do not want to use sets, you could do this: - >>> lst1 = [1,2,3,4,5,6,7,8,9,0,11,12,13]
-
>>> lst2 = [5,6,7,12,45,67,89,99]
-
>>> [i for i in lst1+lst2 if i not in lst1 or i not in lst2]
-
[1, 2, 3, 4, 8, 9, 0, 11, 13, 45, 67, 89, 99]
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mickel Grönroos |
last post by:
Hi!
Are there any standard list methods for getting the intersection and
difference of two lists? (The union is easy ("list1.extend(list2)"),
unless you want it to contain unique values.)
...
|
by: Jeff Wagner |
last post by:
I've spent most of the day playing around with lists and tuples to get a really good grasp on what
you can do with them. I am still left with a question and that is, when should you choose a list or...
|
by: scott289 |
last post by:
Getting the lists of users in a given Domain Group?
For example, our Network people have created a group called MyAppUsers,
and have added certain Users to this group. I need to get a list of...
|
by: Odd-R. |
last post by:
I have to lists, A and B, that may, or may not be equal. If they are not
identical, I want the output to be three new lists, X,Y and Z where X has
all the elements that are in A, but not in B, and...
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4. Let's say I have two scalars, $list1 and $list2.
Both are comma separated lists of ordered, unsigned, unique integers.
An example would be
$list1 = "2,26,345";...
|
by: rshepard |
last post by:
I'm a bit embarrassed to have to ask for help on this, but I'm not finding
the solution in the docs I have here.
Data are assembled for writing to a database table. A representative tuple
looks...
|
by: Shafik |
last post by:
Hello folks,
I am an experienced programmer, but very new to python (2 days). I
wanted to ask: what exactly is the difference between a tuple and a
list? I'm sure there are some, but I can't...
|
by: Petronius |
last post by:
Hallo, does anyone have an idea how to implement difference lists in
Javascript?
Thanks allot in advance
|
by: narutocanada |
last post by:
hi
what is the difference between the two kinds of brackets?
I tried a few examples but I can't make out any real difference:
lst =
print lst
print lst
print lst
lst = (10, 20, 30)
print...
|
by: Syed Khaleel Ahamed |
last post by:
Dear Sir,
I want to get the difference of date/time captured in mysql and present date/time in jsp.
I am using the following code to get, but its getting difference only in hrs, i used...
|
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:
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
| |