473,769 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which module is "set " in?

I want to use the set function like

mylist = ['a', 'b', 'b', 'd', 'e', 'a']
myset = set (mylist)

But I don't know what to import, I tried sys, sets,
they don't work.

What's the easy way to find out the module that
contains a particular function?

_______________ _______________ ____
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
Jul 18 '05 #1
3 1734
Anthony Liu wrote:
I want to use the set function like

mylist = ['a', 'b', 'b', 'd', 'e', 'a']
myset = set (mylist)

But I don't know what to import, I tried sys, sets,
they don't work.
If you're using Python 2.4, they're builtin. If you're using Python
2.3, you'll probably want to do something like:
from sets import Set as set
Python's before 2.3 do not have a set type.
What's the easy way to find out the module that
contains a particular function?


Perhaps the documentation index?

http://docs.python.org/lib/genindex.html

Steve
Jul 18 '05 #2
It's good that you're using Python 2.3, which does have sets available,
as a previous poster mentioned. Users of Python 2.2 or earlier can get
most of the Set functionality using the following class (from Peter
Norvig's utils.py file):

# class Set:
# """This implements the Set class from PEP 218, except it does not
# overload the infix operators.
# Ex: s = Set([1,2,3]); 1 in s ==> True; 4 in s ==> False
# s.add(4); 4 in s ==> True; len(s) ==> 4
# s.discard(999); s.remove(4); 4 in s ==> False
# s2 = Set([3,4,5]); s.union(s2) ==> Set([1,2,3,4,5])
# s.intersection( s2) ==> Set([3])
# Set([1,2,3]) ==> Set([3,2,1]); repr(s) ==> '{1, 2, 3}'
# for e in s: pass"""
#
# def __init__(self, elements=[]):
# self.dict = {}
# for e in elements:
# self.dict[e] = 1
#
# def __contains__(se lf, element):
# return element in self.dict
#
# def __getitem__(sel f, i):
# return self.dict.items ()[i]
#
# def add(self, element):
# self.dict[element] = 1
#
# def remove(self, element):
# del self.dict[element]
#
# def discard(self, element):
# if element in self.dict:
# del self.dict[element]
#
# def pop(self):
# key, val = self.dict.popit em()
# return key
#
# def clear(self):
# self.dict.clear ()
#
# def union(self, other):
# return Set(self).union _update(other)
#
# def intersection(se lf, other):
# return Set(self).inter section_update( other)
#
# def union_update(se lf, other):
# for e in other:
# self.add(e)
# return self
#
# def intersection_up date(self, other):
# for e in self.dict.keys( ):
# if e not in other:
# self.remove(e)
# return self
#
# def issubset(self, other):
# for e in self.dict.keys( ):
# if e not in other:
# return False
# return True
#
# def __iter__(self):
# for e in self.dict:
# yield e
#
# def __len__(self):
# return len(self.dict)
#
# def __cmp__(self, other):
# if self is other: return False
# if not isinstance(othe r, Set): return id(self) - id(other)
# return cmp(self.dict, other.dict)
#
# def __repr__(self):
# return "{%s}" % ", ".join([str(e) for e in self.dict.keys( )])

Michael

--
Michael D. Hartl, Ph.D.
CTO, Quark Sports LLC
http://quarksports.com/

Jul 18 '05 #3
[Michael Hartl]
It's good that you're using Python 2.3, which does have sets available,
as a previous poster mentioned. Users of Python 2.2 or earlier can get
most of the Set functionality using the following class (from Peter
Norvig's utils.py file):


Py2.3's set module also works under Py2.2. Get a copy from viewcvs:

http://tinyurl.com/6lqr3

or
http://cvs.sourceforge.net/viewcvs.p...n&rev=1.43.4.2

Of course, if upgrading to Py2.4 is an option, that is the way to go. If you're
living in a pre 2.2 world without iterators and generators, you're really
missing out.
Raymond Hettinger


Jul 18 '05 #4

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

Similar topics

1
8003
by: Steve | last post by:
I get this message when I tried to make a .MDE of my database. "Compile error in hidden module: Form_frmPurchaseReq" I have been using this database for several months and just thought I would make a .MDE of it and this message came up. Help said, something about a protected module or something..... Could someone enlighten me on this problem?
5
3696
by: Bob | last post by:
Are they different names for the same concept ?
5
15422
by: BH | last post by:
Hi what would be the C# equivalent of a VB.NET file that looks like this: Module Utilities Public Sub UtilitySubOne ( ByVal arg As String) // blah blah End Sub
5
1813
by: Studio P.M. | last post by:
Having built successfully my first HTTP Module prototype (as for Q307996 - HOW TO: Create an ASP.NET HTTP Module ...) without really understanding what I've done, now I kindly ask this community for support to try and master this art; in the form of: - either a reference to a serious book comprehensively describing the matter; - or an answer to such a question as: What does it exactly mean, in C# terms, to implement the "IHttModule...
1
2599
by: Xiao Jianfeng | last post by:
Hello, In pymol I can use "from chempy import Atom" but "import chempy.Atom" doesn't work. It says,"ImportError: No module named Atom". What is going wrong ? Thanks
3
16519
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or something in PHP that I don't have? Do I need to install more Linux packages? Or adjust PHP in some way?
0
2062
by: Shehryar | last post by:
AOA, I urgently want to know the major difference between "Module" and a "Class Module". Plz, reply me as early as possible. Thanx!
16
5666
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
22
1411
by: ZioMiP | last post by:
Hi to all... I'm actually using Tkinter for my GUI... but I need to "put a piece of a web-page in a widget" how can I do? which GUI module do you suggest me to use for do that? or which GUI module do you suggest me to use at all? I'm acutally using Windows Xp but I also use Linux...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
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
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
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...
1
3958
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
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.