[Tutor] Help!
Alan Gauld
alan.gauld at btinternet.com
Mon Jan 25 15:29:07 EST 2016
On 25/01/16 17:39, Chelsea G wrote:
> Hi,
> I am trying to create a keyword search, so that someone can type in a key
> phrase and then the output be the value with the key.
I'm not completely clear what you mean by a key phrase?
Do you mean a phrase matching the keys in your dictionary?(In which case
its easy) or domyou mean a random phrase? In which case what should happen?
> I have some code
> already done but having some trouble getting it to work.
Sadly you haven't posted in plain text so its lost all indentation,
making it nearly unreadable. Can you repost in plain text please?
> class dictionary():
> def __init__(self):
> self.dict = defaultdict(list)
> self.counted_dict = defaultdict(list)
> self.grouped_dict = defaultdict(list)
> self.other_dict = defaultdict(list)
> self.final_dict = defaultdict(list)
> self.total_dict = defaultdict(list)
> self.keyword_dict = defaultdict(list)
> def populate_dict(self, filename):
> with open (filename, 'rb') as f:
> reader = csv.reader(f)
> next(reader, None)
> for row in reader:
> self.dict[row[2]].append(row[3])
...
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list