472,958 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

about data structure --- 'Set'

5
Hello everyone,

If you look at the following tutorial, you will find the great advantage of using 'set' as a data structure.

http://docs.python.org/tut/node7.htm...00000000000000

But it seems I need to import something before using it, otherwise it'll not be recognised. Could anybody please tell me what I should import?

Thanks in advance!
Oct 31 '07 #1
2 1534
bartonc
6,596 Expert 4TB
Hello everyone,

If you look at the following tutorial, you will find the great advantage of using 'set' as a data structure.

http://docs.python.org/tut/node7.htm...00000000000000

But it seems I need to import something before using it, otherwise it'll not be recognised. Could anybody please tell me what I should import?

Thanks in advance!
If your Python version is less than 2.4:
Expand|Select|Wrap|Line Numbers
  1. import Set as set
  2. # or (I think)
  3. from Future import Set as set
Use the as modifier so that you code works with higher versions.

Otherwise, it's as simple as
Expand|Select|Wrap|Line Numbers
  1. >>> set([1,1,3,4,5,5])
  2. set([1, 3, 4, 5])
  3. >>> 
Note that sets are not mutable (just like tuples). I've been using sets lately for their cool ability to subtract from one another:
Expand|Select|Wrap|Line Numbers
  1. >>> set([1,2,3,4,5,6]) - set([4,5,6])
  2. set([1, 2, 3])
  3. >>> 
Oct 31 '07 #2
wxy212
5
If your Python version is less than 2.4:
Expand|Select|Wrap|Line Numbers
  1. import Set as set
  2. # or (I think)
  3. from Future import Set as set
Use the as modifier so that you code works with higher versions.

Otherwise, it's as simple as
Expand|Select|Wrap|Line Numbers
  1. >>> set([1,1,3,4,5,5])
  2. set([1, 3, 4, 5])
  3. >>> 
Note that sets are not mutable (just like tuples). I've been using sets lately for their cool ability to subtract from one another:
Expand|Select|Wrap|Line Numbers
  1. >>> set([1,2,3,4,5,6]) - set([4,5,6])
  2. set([1, 2, 3])
  3. >>> 

cool! thanks a lot. the python version i used was 2.2.... that's why...
Nov 1 '07 #3

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

Similar topics

1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
2
by: Pete | last post by:
Before I get started with the question, does anyone have a (single) good book recommendation for database design? Not an Access-specific book, but something geared toward helping me figure out...
1
by: Andrew Arace | last post by:
I scoured the groups for some hands on code to perform the menial task of exporting table data from an Access 2000 database to Oracle database (in this case, it was oracle 8i but i'm assuming this...
4
by: Thomas Paul Diffenbach | last post by:
Can anyone point me to an open source library of /statically allocated/ data structures? I'm writing some code that would benefit from trees, preferably self balancing, but on an embedded system...
11
by: Hi5 | last post by:
Hi, I am new to access I usedto work in Oracle and Mysql. I am after a way that enables me to populate a database I designed in access with lots of data which can be sorted in excel sheets, ...
3
by: aurora | last post by:
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. ...
12
by: Sam Kong | last post by:
Hi, JavaScript hides its memory structure. I know that numbers, booleans, null and undefined are value types (value is directed saved in a variable). I want to know: - How JavaScript...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
9
by: william | last post by:
When implementing Linked list, stack, or trees, we always use pointers to 'link' the nodes. And every node is always defined as: struct node { type data; //data this node contains ... node *...
7
by: Chad | last post by:
#include <stdio.h> enum Type {DAYS, HOURSMINUTES}; struct Days { int num_days; }; struct HoursMinutes { int num_hours;
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.