Re: [Tutor] dictionary append

2007-11-01 Thread Kent Johnson
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

Re: [Tutor] dictionary append

2007-11-01 Thread bob gailer
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

Re: [Tutor] dictionary append

2007-11-01 Thread Alan Gauld
"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. ..

[Tutor] dictionary append

2007-11-01 Thread Dinesh B Vadhia
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,