Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28779

Re: AttributeError: 'list' object has no attribute 'lower'

From Roy Smith <roy@panix.com>
Newsgroups comp.lang.python
Subject Re: AttributeError: 'list' object has no attribute 'lower'
Date 2012-09-09 10:29 -0400
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <roy-775DEC.10291109092012@news.panix.com> (permalink)
References <df7ab5f7-c273-4a62-b79a-f364f9c2d3b0@googlegroups.com> <roy-838395.13453908092012@news.panix.com> <43a68990-d6cf-4362-8c47-b13ce780b068@googlegroups.com>

Show all headers | View raw


In article <43a68990-d6cf-4362-8c47-b13ce780b068@googlegroups.com>,
 Token Type <typetoken@gmail.com> 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)
> <type '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)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-08 10:13 -0700
  wordnet NLTK Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-08 10:32 -0700
  Re: AttributeError: 'list' object has no attribute 'lower' Roy Smith <roy@panix.com> - 2012-09-08 13:45 -0400
    Re: AttributeError: 'list' object has no attribute 'lower' Cameron Simpson <cs@zip.com.au> - 2012-09-09 09:26 +1000
    Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-09 06:50 -0700
      Re: AttributeError: 'list' object has no attribute 'lower' Roy Smith <roy@panix.com> - 2012-09-09 10:29 -0400
    Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-09 07:00 -0700
      Re: AttributeError: 'list' object has no attribute 'lower' Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-09-10 11:52 +0200
        Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-14 08:01 -0700
          Re: AttributeError: 'list' object has no attribute 'lower' Chris Angelico <rosuav@gmail.com> - 2012-09-15 01:19 +1000
        Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-14 08:01 -0700
          Re: AttributeError: 'list' object has no attribute 'lower' Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-09-14 15:18 +0000
    Re: AttributeError: 'list' object has no attribute 'lower' Token Type <typetoken@gmail.com> - 2012-09-09 07:19 -0700
      Re: AttributeError: 'list' object has no attribute 'lower' Roy Smith <roy@panix.com> - 2012-09-09 10:32 -0400

csiph-web