By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

backport of 'set' to python 2.3?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
"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

P: n/a
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

P: n/a
>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.