Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!feed.news.qwest.net!mpls-nntp-06.inet.qwest.net!news-out.readnews.com!transit3.readnews.com!panix!roy From: Roy Smith Newsgroups: comp.lang.python Subject: Re: AttributeError: 'list' object has no attribute 'lower' Date: Sun, 09 Sep 2012 10:29:11 -0400 Organization: PANIX Public Access Internet and UNIX, NYC Lines: 50 Message-ID: References: <43a68990-d6cf-4362-8c47-b13ce780b068@googlegroups.com> NNTP-Posting-Host: localhost X-Trace: reader1.panix.com 1347200952 18504 127.0.0.1 (9 Sep 2012 14:29:12 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Sun, 9 Sep 2012 14:29:12 +0000 (UTC) User-Agent: MT-NewsWatcher/3.5.3b3 (Intel Mac OS X) Xref: csiph.com comp.lang.python:28779 In article <43a68990-d6cf-4362-8c47-b13ce780b068@googlegroups.com>, Token Type wrote: > Thanks very much for all of your tips. Take noun as an example. First, I need > find all the lemma_names in all the synsets whose pos is 'n'. Second, for > each lemma_name, I will check all their sense number. > > 1) Surely,we can know the number of synset whose pos is noun by > >>> len([synset for synset in wn.all_synsets('n')]) > 82115 > > However, confusingly it is unsuccessful to get a list of lemma names of these > synsets by > >>> lemma_list = [synset.lemma_names for synset in wn.all_synsets('n')] > >>> lemma_list[:20] > [['entity'], ['physical_entity'], ['abstraction', 'abstract_entity'], > ['thing'], ['object', 'physical_object'], ['whole', 'unit'], ['congener'], > ['living_thing', 'animate_thing'], ['organism', 'being'], ['benthos'], > ['dwarf'], ['heterotroph'], ['parent'], ['life'], ['biont'], ['cell'], > ['causal_agent', 'cause', 'causal_agency'], ['person', 'individual', > 'someone', 'somebody', 'mortal', 'soul'], ['animal', 'animate_being', > 'beast', 'brute', 'creature', 'fauna'], ['plant', 'flora', 'plant_life']] > >>> type(lemma_list) > > > Though the lemma_list is a list in the above codes, it contains so many > unnecessary [ and ]. How come it is like this? But what we desire and expect > is a list without this brackets. Confused, I am really curious to know why. It looks like synset.lemma_names gets you a list. And then you're taking all those lists and forming them into a list of lists: >>> lemma_list = [synset.lemma_names for synset in wn.all_synsets('n')] I think what you want to study is the difference between list.append() and list.extend(). When you use the list builder syntax, you're essentially writing a loop which does append operations. The above is the same as if you wrote: lemma_list = list() for synset in wn.all_synsets('n'): lemma_list.append(synset.lemma_names) and I think what you're looking for is: lemma_list = list() for synset in wn.all_synsets('n'): lemma_list.extend(synset.lemma_names)