473,288 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

backport of 'set' to python 2.3?

Does anyone have a pure python implementation of the builtin 'set'
object so that I could use that in python 2.3? If this would be the
case that would be really great as I wouldn't have to change my code
that runs happily on 2.5 and makes use of 'set'. Speed and performance
doesn't matter, any implementation that does exactly the same as the
builtin 'set' in 2.5 would be great.

Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
Jun 27 '08 #1
3 1396
"Daniel Fetchinson" <fe********@googlemail.comwrites:
Does anyone have a pure python implementation of the builtin 'set'
object so that I could use that in python 2.3?
Yes. You have one in Python 2.3 already
<URL:http://www.python.org/doc/2.3.5/lib/module-sets.html>, it's just
not a builtin.
If this would be the case that would be really great as I wouldn't
have to change my code that runs happily on 2.5
You will, but it's as simple as:

try:
set()
except NameError:
from sets import Set as set

You then know that 'set' refers to the set type from that point on (or
you're not on a version of Python that has a 'set' type at all).

--
\ "I have a large seashell collection, which I keep scattered on |
`\ the beaches all over the world. Maybe you've seen it." -- |
_o__) Steven Wright |
Ben Finney
Jun 27 '08 #2
Daniel Fetchinson wrote:
Does anyone have a pure python implementation of the builtin 'set'
object so that I could use that in python 2.3? If this would be the
case that would be really great as I wouldn't have to change my code
that runs happily on 2.5 and makes use of 'set'. Speed and performance
doesn't matter, any implementation that does exactly the same as the
builtin 'set' in 2.5 would be great.

Cheers,
Daniel
From "What's new in Python 2.4":

Python 2.3 introduced the sets module. C implementations of set data types have
now been added to the Python core as two new built-in types, set(iterable) and
frozenset(iterable). They provide high speed operations for membership testing,
for eliminating duplicates from sequences, and for mathematical operations like
unions, intersections, differences, and symmetric differences.

You should be able to use sets module in 2.3.

-Larry
Jun 27 '08 #3
>Does anyone have a pure python implementation of the builtin 'set'
>object so that I could use that in python 2.3?

Yes. You have one in Python 2.3 already
<URL:http://www.python.org/doc/2.3.5/lib/module-sets.html>, it's just
not a builtin.
>If this would be the case that would be really great as I wouldn't
have to change my code that runs happily on 2.5

You will, but it's as simple as:

try:
set()
except NameError:
from sets import Set as set

You then know that 'set' refers to the set type from that point on (or
you're not on a version of Python that has a 'set' type at all).
Thanks Ben! I should have checked the docs........

Cheers,
Daniel
--
Psss, psss, put it down! - http://www.cafepress.com/putitdown
Jun 27 '08 #4

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

Similar topics

1
by: Pierre Rouleau | last post by:
I can't remember where/how sys.path is set (aside from the automatically loaded site.py) and i get a strange entry in it. Can anyone remind me where/how to control sys.path on a Win32 machine (i'm...
9
by: Pierre Barbier de Reuille | last post by:
Ok, I first want to stress that I looked through the newsgroups archives (on Google) for an answer to my question, but I didn't find it. It's about the interface of the set classes as defined in...
8
by: bearophileHUGS | last post by:
I'm frequently using Py2.4 sets, I find them quite useful, and I like them, even if they seem a little slower than dicts. Sets also need the same memory of dicts (can they be made to use less...
3
by: Joe | last post by:
Back in March I submitted a patch for cgi.py to sourceforge to fix a problem with the handling of an invalid REQUEST_METHOD. I thought I followed all the steps to properly submit the bug and...
90
by: Christoph Zwerschke | last post by:
Ok, the answer is easy: For historical reasons - built-in sets exist only since Python 2.4. Anyway, I was thinking about whether it would be possible and desirable to change the old behavior in...
14
by: vatamane | last post by:
This has been bothering me for a while. Just want to find out if it just me or perhaps others have thought of this too: Why shouldn't the keyset of a dictionary be represented as a set instead of a...
22
by: bearophileHUGS | last post by:
>From this interesting blog entry by Lawrence Oluyede: http://www.oluyede.org/blog/2006/07/05/europython-day-2/ and the Py3.0 PEPs, I think the people working on Py3.0 are doing a good job, I am...
9
by: Stef Mientki | last post by:
Is it possible to change the searchpath for modules on the flight, under winXP ? Most preferred is some command to extend the searchpath. (the environment variable PYTHONPATH needs a reboot) ...
7
by: =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= | last post by:
s0 = set() In that case, there is always a trivial answer. As I can use any function which takes and returns sets, and as I shall come up with a function that returns s0, I just use the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
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 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.