469,306 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

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 1341
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Pierre Rouleau | last post: by
9 posts views Thread by Pierre Barbier de Reuille | last post: by
8 posts views Thread by bearophileHUGS | last post: by
90 posts views Thread by Christoph Zwerschke | last post: by
22 posts views Thread by bearophileHUGS | last post: by
9 posts views Thread by Stef Mientki | last post: by
7 posts views Thread by =?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Geralt96 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.