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!
2 1555
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: - import Set as set
-
# or (I think)
-
from Future import Set as set
Use the as modifier so that you code works with higher versions.
Otherwise, it's as simple as -
>>> set([1,1,3,4,5,5])
-
set([1, 3, 4, 5])
-
>>>
Note that sets are not mutable (just like tuples). I've been using sets lately for their cool ability to subtract from one another: -
>>> set([1,2,3,4,5,6]) - set([4,5,6])
-
set([1, 2, 3])
-
>>>
If your Python version is less than 2.4: - import Set as set
-
# or (I think)
-
from Future import Set as set
Use the as modifier so that you code works with higher versions.
Otherwise, it's as simple as -
>>> set([1,1,3,4,5,5])
-
set([1, 3, 4, 5])
-
>>>
Note that sets are not mutable (just like tuples). I've been using sets lately for their cool ability to subtract from one another: -
>>> set([1,2,3,4,5,6]) - set([4,5,6])
-
set([1, 2, 3])
-
>>>
cool! thanks a lot. the python version i used was 2.2.... that's why...
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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,
...
|
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.
...
|
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...
|
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...
|
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 *...
|
by: Chad |
last post by:
#include <stdio.h>
enum Type {DAYS, HOURSMINUTES};
struct Days {
int num_days;
};
struct HoursMinutes {
int num_hours;
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
| |