[Tutor] efficient method to search between two lists
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Mar 23 06:00:54 CET 2006
> Although dictionary is superfast, due to duplications
> in both columns of list_a, a dictionary option falls
> out.
Hi Srinivas,
A dictionary method can work perfectly well.
The assumption that I think is being made is that dictionary values are
restricted to single values. But dictionaries are more general than this.
We can make dictionaries that map from strings to lists of things.
For example:
#######
sample = { 'a': ['alphabet', 'artichoke', 'antelope'],
'b': ['beta', 'brocolli', 'brontosaurus'],
'g': ['gamma', 'grub', 'gnome'] }
#######
is a perfectly good dictionary.
More information about the Tutor
mailing list