Searching and manipulating lists of tuples
Sion Arrowsmith
siona at chiark.greenend.org.uk
Mon Jun 12 11:24:24 EDT 2006
Steve Holden <steve at holdenweb.com> 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) (assuming
some other part of the program wants that list representation).
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list