On Nov 24, 6:38 pm, Hrvoje Niksic [EMAIL PROTECTED] wrote:
samwyse [EMAIL PROTECTED] writes:
create a hash that maps your keys to themselves, then use the values
of that hash as your keys.
The atom function you describe already exists under the name
intern.
D'oh! That's what I get for
On Nov 24, 4:44 am, Licheng Fang [EMAIL PROTECTED] wrote:
Yes, millions. In my natural language processing tasks, I almost
always need to define patterns, identify their occurrences in a huge
data, and count them. Say, I have a big text file, consisting of
millions of words, and I want to
On Nov 27, 10:45 am, Steven D'Aprano
[EMAIL PROTECTED] wrote:
On Sun, 25 Nov 2007 02:42:36 -0800, Licheng Fang wrote:
I mentioned trigram counting as an illustrative case. In fact, you'll
often need to define patterns more complex than that, and tens of
megabytes of text may generate
On Nov 27, 2007 7:16 AM, Licheng Fang [EMAIL PROTECTED] wrote:
On Nov 27, 10:45 am, Steven D'Aprano
[EMAIL PROTECTED] wrote:
On Sun, 25 Nov 2007 02:42:36 -0800, Licheng Fang wrote:
I mentioned trigram counting as an illustrative case. In fact, you'll
often need to define patterns more
On Sun, 25 Nov 2007 02:42:36 -0800, Licheng Fang wrote:
I mentioned trigram counting as an illustrative case. In fact, you'll
often need to define patterns more complex than that, and tens of
megabytes of text may generate millions of them, and I've observed they
quickly ate up the 8G memory
Steven D'Aprano wrote:
store = {}
def atom(str):
global store
if str not in store:
store[str] = str
return store[str]
Oh lordy, that's really made my day! That's the funniest piece of code
I've seen for a long time! Worthy of being submitted to the DailyWTF.
On Nov 25, 5:59 am, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
On Sat, 24 Nov 2007 03:44:59 -0800, Licheng Fang wrote:
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
Licheng Fang wrote:
I find myself frequently in need of classes like this for
On Sun, 25 Nov 2007 10:39:38 +0100, Peter Otten wrote:
So if you are going to submit Sam's function make sure to bundle it with
this little demo...
Well Peter, I was going to reply with a comment about not changing the
problem domain (tuples of ints to trigrams from a text file for natural
On Nov 24, 6:42 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
This has nothing, absolutely NOTHING, to do with memoization. Memoization
trades off memory for time, allowing slow functions to return results
faster at the cost of using more memory. The OP wants to save memory,
Steven D'Aprano wrote:
On Sun, 25 Nov 2007 01:38:51 +0100, Hrvoje Niksic wrote:
samwyse [EMAIL PROTECTED] writes:
create a hash that maps your keys to themselves, then use the values of
that hash as your keys.
The atom function you describe already exists under the name intern.
Not
I mean, all the class instances that equal to each other should be
reduced into only one instance, which means for instances of this
class there's no difference between a is b and a==b.
Thank you.
--
http://mail.python.org/mailman/listinfo/python-list
I find myself frequently in need of classes like this for two reasons.
First, it's efficient in memory. Second, when two instances are
compared for equality only their pointers are compared. (I think
that's how Python compares 'str's.
On Nov 24, 6:31 pm, Licheng Fang [EMAIL PROTECTED] wrote:
I
Licheng Fang wrote:
I mean, all the class instances that equal to each other should be
reduced into only one instance, which means for instances of this
class there's no difference between a is b and a==b.
If you only want that if a == b is True also a is b is True,
overload the is_ attribute
Licheng Fang wrote:
I find myself frequently in need of classes like this for two
reasons. First, it's efficient in memory.
Are you using millions of objects, or MB size objects? Otherwise,
this is no argument.
BTW, what happens if you, by some operation, make a == b, and
afterwards change b
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
Licheng Fang wrote:
I find myself frequently in need of classes like this for two
reasons. First, it's efficient in memory.
Are you using millions of objects, or MB size objects? Otherwise,
this is no argument.
Yes,
Licheng Fang wrote:
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
BTW, what happens if you, by some operation, make a == b, and
afterwards change b so another object instance must be created?
This instance management is quite a runtime overhead.
I probably need this class to be
On Nov 24, 5:44 am, Licheng Fang [EMAIL PROTECTED] wrote:
Yes, millions. In my natural language processing tasks, I almost
always need to define patterns, identify their occurrences in a huge
data, and count them. [...] So I end up with unnecessary
duplicates of keys. And this can be a great
On Sat, 24 Nov 2007 13:40:40 +0100, Bjoern Schliessmann wrote:
Licheng Fang wrote:
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
Wow, I didn't know this. But exactly how Python manage these
strings?
I don't know (use the source, Luke). :) Or perhaps there is a Python
Elder here that
On Nov 24, 9:42 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote:
On Sat, 24 Nov 2007 13:40:40 +0100, Bjoern Schliessmann wrote:
Licheng Fang wrote:
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
Wow, I didn't know this. But exactly how Python manage these
strings?
I don't know
Licheng Fang a écrit :
I mean, all the class instances that equal to each other should be
reduced into only one instance, which means for instances of this
class there's no difference between a is b and a==b.
Here's a QD attempt - without any garantee, and to be taylored to your
needs.
On Nov 24, 10:35 am, Licheng Fang [EMAIL PROTECTED] wrote:
Thanks. Then, is there a way to make python treat all strings this
way, or any other kind of immutable objects?
The word generally used is 'atom' when referring to strings that are
set up such that 'a == b' implies 'a is b'. This is
On Nov 24, 5:44 am, Licheng Fang [EMAIL PROTECTED] wrote:
Yes, millions. In my natural language processing tasks, I almost
always need to define patterns, identify their occurrences in a huge
data, and count them. Say, I have a big text file, consisting of
millions of words, and I want to
On Sat, 24 Nov 2007 03:44:59 -0800, Licheng Fang wrote:
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
Licheng Fang wrote:
I find myself frequently in need of classes like this for two
reasons. First, it's efficient in memory.
Are you using millions of objects,
On Sat, 24 Nov 2007 04:54:43 -0800, samwyse wrote:
create a hash that maps your keys to themselves, then use the values of
that hash as your keys.
store = {}
def atom(str):
global store
if str not in store:
store[str] = str
return store[str]
Oh lordy,
On Sat, 24 Nov 2007 12:00:25 +0100, Bjoern Schliessmann wrote:
Licheng Fang wrote:
I mean, all the class instances that equal to each other should be
reduced into only one instance, which means for instances of this class
there's no difference between a is b and a==b.
If you only want that
On Nov 24, 4:59 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
On Sat, 24 Nov 2007 03:44:59 -0800, Licheng Fang wrote:
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
Licheng Fang wrote:
I find myself frequently in need of classes like this for two
reasons.
Steven D'Aprano wrote:
No advantage? That's for sure. There is no is_ attribute of
generic classes, and even if there was, it would have no special
meaning.
Argl, I confused the operator module's attributes with objects ;)
Regards,
Björn
--
BOFH excuse #378:
Operators killed by year
On Sat, 24 Nov 2007 14:58:50 -0800, George Sakkis wrote:
On Nov 24, 4:59 pm, Steven D'Aprano
[EMAIL PROTECTED] wrote:
On Sat, 24 Nov 2007 03:44:59 -0800, Licheng Fang wrote:
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet-
[EMAIL PROTECTED] wrote:
Licheng Fang wrote:
I find myself
samwyse [EMAIL PROTECTED] writes:
create a hash that maps your keys to themselves, then use the values
of that hash as your keys.
The atom function you describe already exists under the name
intern.
--
http://mail.python.org/mailman/listinfo/python-list
On Sun, 25 Nov 2007 01:38:51 +0100, Hrvoje Niksic wrote:
samwyse [EMAIL PROTECTED] writes:
create a hash that maps your keys to themselves, then use the values of
that hash as your keys.
The atom function you describe already exists under the name intern.
Not really. intern() works very
Steven D'Aprano [EMAIL PROTECTED] writes:
On Sun, 25 Nov 2007 01:38:51 +0100, Hrvoje Niksic wrote:
samwyse [EMAIL PROTECTED] writes:
create a hash that maps your keys to themselves, then use the values of
that hash as your keys.
The atom function you describe already exists under the
On Nov 24, 7:42 pm, Steven D'Aprano
To the OP: yes, your use case is quite valid; the keyword you are
looking for is memoize. You can find around a dozen of recipes in the
Cookbook and posted in this list; here's one starting point:
32 matches
Mail list logo