Hi list,
If I have a bunch of sets:
a = set((1, 2, 3))
b = set((2, 3))
c = set((1, 3))
.....
What's the cleanest way to say:
1) Give me a list of the items that are in all of the sets? (3 in the
above example)
2) Give me a list of the items that are not in all of the sets? (1,2 in
the above example)
Thanks, 6 1816
Oops. Forgot to mention, I am still using 2.3.
John Henry wrote:
Hi list,
If I have a bunch of sets:
a = set((1, 2, 3))
b = set((2, 3))
c = set((1, 3))
....
What's the cleanest way to say:
1) Give me a list of the items that are in all of the sets? (3 in the
above example)
2) Give me a list of the items that are not in all of the sets? (1,2 in
the above example)
Thanks,
[John Henry]
If I have a bunch of sets:
a = set((1, 2, 3))
b = set((2, 3))
c = set((1, 3))
....
What's the cleanest way to say:
1) Give me a list of the items that are in all of the sets? (3 in the
above example)
list(a & b & c)
2) Give me a list of the items that are not in all of the sets? (1,2 in
the above example)
list((a | b | c) - (a & b & c))
Aye!
I did a:
a and b and c
Bonk!
Thanks,
Tim Peters wrote:
[John Henry]
If I have a bunch of sets:
a = set((1, 2, 3))
b = set((2, 3))
c = set((1, 3))
....
What's the cleanest way to say:
1) Give me a list of the items that are in all of the sets? (3 in the
above example)
list(a & b & c)
2) Give me a list of the items that are not in all of the sets? (1,2 in
the above example)
list((a | b | c) - (a & b & c))
At Wednesday 25/10/2006 21:12, John Henry wrote:
>Oops. Forgot to mention, I am still using 2.3.
try: set
except NameError: from sets import Set as set
and the code will work almost exactly the same in 2.3/2.4
1) Give me a list of the items that are in all of the sets? (3 in the
above example)
a & b & c
& is the intersection operator.
2) Give me a list of the items that are not in all of the sets? (1,2 in
the above example)
(a | b | c) - (a & b & c)
(take the union of all items) except (the ones that are
simultaneously in all sets)
--
Gabriel Genellina
Softlab SRL
__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis!
¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar
John Henry wrote:
What's the cleanest way to say:
1) Give me a list of the items that are in all of the sets? (3 in the
above example)
2) Give me a list of the items that are not in all of the sets? (1,2 in
the above example)
Thanks,
If you have an arbitrary list of sets, reduce comes in handy:
See this recipe: http://aspn.activestate.com/ASPN/Coo.../Recipe/476215
pysets = [set((1, 2, 3)), set((2, 3)), set((1, 3))]
pyreduce(set.intersection, sets)
set([3])
pyreduce(set.union, sets)
set([1, 2, 3])
pyreduce(set.union, sets) - reduce(set.intersection, sets)
set([1, 2])
--
Brian Beck
Adventurer of the First Order
Oh, great. Learn something new everyday.
For this, what I did was to build up a string, and then use eval on the
string. Very ugly.
Now I can simply do a reduce.
Thanks,
Brian Beck wrote:
John Henry wrote:
What's the cleanest way to say:
1) Give me a list of the items that are in all of the sets? (3 in the
above example)
2) Give me a list of the items that are not in all of the sets? (1,2 in
the above example)
Thanks,
If you have an arbitrary list of sets, reduce comes in handy:
See this recipe: http://aspn.activestate.com/ASPN/Coo.../Recipe/476215
pysets = [set((1, 2, 3)), set((2, 3)), set((1, 3))]
pyreduce(set.intersection, sets)
set([3])
pyreduce(set.union, sets)
set([1, 2, 3])
pyreduce(set.union, sets) - reduce(set.intersection, sets)
set([1, 2])
--
Brian Beck
Adventurer of the First Order
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Thom McGrath |
last post by:
I have a text area that people should type in (duh) which will later be
displayed for other users via HTML. I've taken care of the HTML aspect
in a pretty cool way, but I worry about character sets...
|
by: flyingfred0 |
last post by:
A small software team (developers, leads and even the manager when he's
had time) has been using (wx)Python/PostgreSQL for over 2 years and
developed a successful 1.0 release of a client/server...
|
by: Ryan R. Rosario |
last post by:
Hello -
I am working on a scheduling application that has many "rules" for
scheduling people. I throw each person into the set that corresponds
to 2 teams. Then I split this large group (of...
|
by: Darko Jovisic |
last post by:
Hi!
Another silly question:
If a stored procedure returns multiple result sets, how do I choose the one
I want to insert into a table?
For example sp_spaceused returns two result sets if...
|
by: randy.p.ho |
last post by:
Using JDBC, is there a way to call a stored procedure with multiple
return values? Thanks.
|
by: Stanley Sinclair |
last post by:
I have a need to return multiple result sets from a stored procedure.
Want that SP to call others to get the data.
Win2003, db2 8.1.5.
Can't figure out how to handle open cursors, and return...
|
by: mark |
last post by:
I have an asp.net ecommerce web application on a remote web server.
I'm using an Access database on the back end. I've notice a few
strange things. When I mimic an multiple user environment by...
|
by: randall g |
last post by:
I have a stored procedure which returns multiple result sets, enclosing
each in its own tag. This works in ADO but not ADO.NET, where an error
is returned by ExecuteXmlReader:
"Invalid command...
|
by: Scott |
last post by:
Front-end Access 2000
I have a stored procedure that has 2 parameters BusinessUnitID and
Year.
It returns multiple record sets (5 to be exact).
I thought I could use a Pass through query but...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |