473,804 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dealing with multiple sets

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,

Oct 25 '06 #1
6 1861
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,
Oct 25 '06 #2
[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))
Oct 25 '06 #3
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))
Oct 26 '06 #4
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
Oct 26 '06 #5
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.in tersection, sets)
set([3])

pyreduce(set.un ion, sets)
set([1, 2, 3])

pyreduce(set.un ion, sets) - reduce(set.inte rsection, sets)
set([1, 2])

--
Brian Beck
Adventurer of the First Order
Oct 26 '06 #6
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.in tersection, sets)
set([3])

pyreduce(set.un ion, sets)
set([1, 2, 3])

pyreduce(set.un ion, sets) - reduce(set.inte rsection, sets)
set([1, 2])

--
Brian Beck
Adventurer of the First Order
Oct 26 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2026
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 now. Everything works for me, but I use UTF-8. When the form is submitted, how do I know what character set the data is coming in? I need to know this to perform htmlentities on the data and have it work properly. All my pages are defined as...
44
3796
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 product. A marketing/product manager has brought in additional management and "architecture" experts to propose moving the entire thing to a Java (application server) platform for the next release. They want a "scalable, enterprise solution"...
1
7785
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 everybody) into 3 groups (indicating which day they will work a particular shift). So I have two disjoint sets: teamA and teamB. and I have three sets: day1, day2, day3 (not divided by team). and so on...
2
3626
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 object name is ommited. I only need the first result set. How do I do that?
4
10691
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
5
8684
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 >1 result sets. Thought about global temp tables.
6
539
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 surfin it in multiple browsers simultaneously the site generates a generic runtime error after awhile. I'm thinking this has something to do with my access database and multiple connections. I'm using forms authentication with a login page. Is...
1
2353
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 sent to ExecuteXmlReader. The command must return an Xml result." The procedure looks like this: create procedure xxx as select '<tag1>'
12
17673
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 that only returns the first record set. I thought I could use ADO but that does not seem to work. I get an Error
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10354
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9175
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.