bob gailer wrote:
> if key not in keywords:
>keywords[key] = []
> keywords[key].append(value)
This can be written more succinctly as
keywords.setdefault(key, []).append(value)
or in Python 2.5:
from collections import defaultdict
keywords = defaultdict(list)
...
keywords[key
Dinesh B Vadhia wrote:
> Hello! I'm creating a dictionary called keywords that has multiple
> entries each with a variable list of values eg.
>
> keywords[1] = [1, 4, 6, 3]
> keywords[2] = [67,2]
> keywords[3] = [2, 8, 5, 66, 3, 23]
> etc.
>
> The keys and respective values (both are integers
"Dinesh B Vadhia" <[EMAIL PROTECTED]> wrote
keywords[1] = [1, 4, 6, 3]
keywords[2] = [67,2]
keywords[3] = [2, 8, 5, 66, 3, 23]
etc.
The keys and respective values (both are integers) are read
in from a file. For each key, the value is append'ed until
the next key. Here is the code.
..
Hello! I'm creating a dictionary called keywords that has multiple entries
each with a variable list of values eg.
keywords[1] = [1, 4, 6, 3]
keywords[2] = [67,2]
keywords[3] = [2, 8, 5, 66, 3, 23]
etc.
The keys and respective values (both are integers) are read in from a file.
For each key,