Hello,
I'm wondering if there's a quick way of resolving this problem.
In a program, I have a list of tuples of form (str,int), where int is a
count of how often str occurs
e.g. L = [ (X,1),(Y,2)] would mean X occurs once and Y occurs
twice
If I am given a string, I want to search L to see if
MTD wrote:
Hello,
I'm wondering if there's a quick way of resolving this problem.
In a program, I have a list of tuples of form (str,int), where int is a
count of how often str occurs
...
So clearly that doesn't work... any ideas?
Yes, use the proper tool for the job. Tuples are
MTD wrote:
Hello,
I'm wondering if there's a quick way of resolving this problem.
In a program, I have a list of tuples of form (str,int), where int is a
count of how often str occurs
e.g. L = [ (X,1),(Y,2)] would mean X occurs once and Y occurs
twice
If I am given a string, I want
MTD wrote:
Hello,
I'm wondering if there's a quick way of resolving this problem.
In a program, I have a list of tuples of form (str,int), where int is a
count of how often str occurs
e.g. L = [ (X,1),(Y,2)] would mean X occurs once and Y occurs
twice
If I am given a string, I want to
Yes, use the proper tool for the job. Tuples are immutable (they are
read-only once created). Instead use a dictionary. They key would be
your string, the value would be the count.
Wow, I really should have thought of that! Thanks.
--
http://mail.python.org/mailman/listinfo/python-list
MTD wrote:
Hello,
I'm wondering if there's a quick way of resolving this problem.
In a program, I have a list of tuples of form (str,int), where int is a
count of how often str occurs
e.g. L = [ (X,1),(Y,2)] would mean X occurs once and Y occurs
twice
If I am given a string, I want to
Steve Holden [EMAIL PROTECTED] wrote:
def algorith(d, s):
if s in d:
d[s] += 1
else:
d[s] = 1
def algorith(d, s):
d[s] = d.get(s, 0) + 1
And the OP should note that converting between dict d and list of
pairs L is simply a matter of L = d.items() and d = dict(L)
MTD wrote:
Hello,
I'm wondering if there's a quick way of resolving this problem.
In a program, I have a list of tuples of form (str,int), where int is a
count of how often str occurs
e.g. L = [ (X,1),(Y,2)] would mean X occurs once and Y occurs
twice
If I am given a string, I want