Searching and manipulating lists of tuples

Mike Kent mrmakent at cox.net
Mon Jun 12 15:15:10 CEST 2006


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 immutable (they are
read-only once created).  Instead use a dictionary.  They key would be
your string, the value would be the count.

Also, don't use 'str' as the name for a string, as it shadows the
built-in 'str' function.




More information about the Python-list mailing list