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


Groups > comp.lang.python > #28757

Re: Is there a unique method in python to unique a list?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <typetoken@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'happen?': 0.09; 'subject:method': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; 'def': 0.10; 'subject:python': 0.11; 'iteration': 0.16; 'operation.': 0.16; 'statement.': 0.16; '>>>': 0.18; 'variable': 0.20; 'thanks.': 0.21; 'runs': 0.22; 'cc:2**0': 0.23; 'cc:no real name:2**0': 0.24; 'second': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'separate': 0.27; 'subject:list': 0.28; 'directly,': 0.29; 'probably': 0.29; 'skip:s 30': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'faster': 0.35; 'skip:l 30': 0.35; 'doing': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'why': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'skip:l 20': 0.38; 'instead': 0.39; "you'll": 0.62; 'subject:there': 0.65
Newsgroups comp.lang.python
Date Sat, 8 Sep 2012 23:44:59 -0700 (PDT)
In-Reply-To <mailman.405.1347172371.27098.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=221.127.246.219; posting-account=mbqf2AoAAAAgAZURfwG566lEnhttS2f1
References <c44aff41-71ed-4323-9184-9c87bd0e1119@googlegroups.com> <60A480B7378343149401A424A682AF34@gmail.com> <CAE5RzXmmGF-w0qHG1F6J5yBMMUptzmGmTqpjh21gf8Yg0A1U_w@mail.gmail.com> <C6FCB83691994615873009528A6C0CD7@gmail.com> <CAE5RzXnjE+UqZj5Ofk2i0F=9U7ZGaAi2D+odwZbUHz0_bYQbzg@mail.gmail.com> <mailman.405.1347172371.27098.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 221.127.246.219
MIME-Version 1.0
Subject Re: Is there a unique method in python to unique a list?
From Token Type <typetoken@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.407.1347173102.27098.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1347173102 news.xs4all.nl 6952 [2001:888:2000:d::a6]:37825
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:28757

Show key headers only | View raw


 
> Try backdenting that statement. You're currently doing it at every
> 
> iteration of the loop - that's why it's so much slower.

Thanks. I works now.

>>> def average_polysemy(pos):
	synset_list = list(wn.all_synsets(pos))
	sense_number = 0
	lemma_list = []
	for synset in synset_list:
		lemma_list.extend(synset.lemma_names)		
	for lemma in list(set(lemma_list)):
		sense_number_new = len(wn.synsets(lemma, pos))
		sense_number = sense_number + sense_number_new
	return sense_number/len(set(lemma_list))

>>> average_polysemy('n')
1

 
> But you'll probably find it better to work with the set directly,
> 
> instead of uniquifying a list as a separate operation.

Yes, the following second methods still runs faster if I don't give a separate variable name to list(set(lemma_list)). Why will this happen?

>>> def average_polysemy(pos):
	synset_list = list(wn.all_synsets(pos))
	sense_number = 0
	lemma_list = []
	for synset in synset_list:
		lemma_list.extend(synset.lemma_names)		
	for lemma in list(set(lemma_list)):
		sense_number_new = len(wn.synsets(lemma, pos))
		sense_number = sense_number + sense_number_new
	return sense_number/len(set(lemma_list))

>>> average_polysemy('n')
1

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


Thread

Is there a unique method in python to unique a list? Token Type <typetoken@gmail.com> - 2012-09-08 22:43 -0700
  Re: Is there a unique method in python to unique a list? Chris Angelico <rosuav@gmail.com> - 2012-09-09 15:48 +1000
  Re: Is there a unique method in python to unique a list? Chris Angelico <rosuav@gmail.com> - 2012-09-09 16:32 +1000
    Re: Is there a unique method in python to unique a list? Token Type <typetoken@gmail.com> - 2012-09-08 23:44 -0700
      Re: Is there a unique method in python to unique a list? Paul Rubin <no.email@nospam.invalid> - 2012-09-09 01:41 -0700
        Re: Is there a unique method in python to unique a list? Paul Rubin <no.email@nospam.invalid> - 2012-09-09 02:06 -0700
        Re: Is there a unique method in python to unique a list? Token Type <typetoken@gmail.com> - 2012-09-09 06:44 -0700
          Re: Is there a unique method in python to unique a list? Chris Angelico <rosuav@gmail.com> - 2012-09-10 00:13 +1000
  Re: Is there a unique method in python to unique a list? Serhiy Storchaka <storchaka@gmail.com> - 2012-09-09 11:36 +0300

csiph-web