On Aug 19, 4:19 pm, Neal Becker ndbeck...@gmail.com wrote:
What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B? (in this particular case, these
sequences are strings, if that matters).
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12)
On Aug 19, 4:19 pm, Neal Becker ndbeck...@gmail.com wrote:
What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B? (in this particular case, these
sequences are strings, if that matters).
Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12)
Jan Kaliszewski wrote:
20-08-2009 o 13:01:29 Neal Becker ndbeck...@gmail.com wrote:
I meant #occurrences of characters from the set A in string B
But:
1) separately for each element of A? (see Simon's sollution with
defaultdict)
2) or total number of all occurrences of elements of
Jan Kaliszewski wrote:
20-08-2009 o 01:19:24 Neal Becker ndbeck...@gmail.com wrote:
What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B? (in this particular case, these
sequences are strings, if that matters).
If you mean: to
Neal Becker wrote:
I meant #occurrences of characters from the set A in string B
If a contains few characters:
n = sum(b.count(c) for c in a)
If a contains many characters:
identity = .join(map(chr, range(256)))
n = len(b) - len(b.translate(identity, a))
Peter
--
a = set(a)
n = sum(item in a for item in b)
Why set? Does it matter if I say that items in A are already unique?
Sets are hash-based, so it's (most probably) far more efficient for
sets than for sequences (especially if we say about big/long ones).
Regards,
*j
--
Jan Kaliszewski
What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B? (in this particular case, these
sequences are strings, if that matters).
--
http://mail.python.org/mailman/listinfo/python-list
20-08-2009 o 01:19:24 Neal Becker ndbeck...@gmail.com wrote:
What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B? (in this particular case, these
sequences are strings, if that matters).
If you mean: to count occurences of each
On Aug 19, 8:17 pm, Jan Kaliszewski z...@chopin.edu.pl wrote:
20-08-2009 o 01:19:24 Neal Becker ndbeck...@gmail.com wrote:
What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B? (in this particular case, these
sequences are strings,
On Wed, 19 Aug 2009, Neal Becker wrote:
What would be a time efficient way to count the number of occurrences of
elements of sequence A in sequence B? (in this particular case, these
sequences are strings, if that matters).
If A and B are rather lengthy, then maybe build a tree from
On Aug 20, 12:12 pm, Simon Forman sajmik...@gmail.com wrote:
On Aug 19, 8:17 pm, Jan Kaliszewski z...@chopin.edu.pl wrote:
If you mean: to count non overlaping occurences of string A in B
-- simply:
B.count(A)
You don't want to use count() in a case like this because it iterates
On Aug 19, 11:34 pm, John Machin sjmac...@lexicon.net wrote:
On Aug 20, 12:12 pm, Simon Forman sajmik...@gmail.com wrote:
On Aug 19, 8:17 pm, Jan Kaliszewski z...@chopin.edu.pl wrote:
If you mean: to count non overlaping occurences of string A in B
-- simply:
B.count(A)
You
12 matches
Mail list logo