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


Groups > comp.lang.python > #2513

Re: Problem regarding returning list

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'displayed': 0.03; 'modified': 0.05; 'int,': 0.07; 'counting': 0.09; 'dict': 0.09; 'subclass': 0.09; 'subject:Problem': 0.09; 'sun,': 0.09; 'am,': 0.14; 'wrote:': 0.14; 'declaring': 0.16; 'example?': 0.16; 'item:': 0.16; 'pointers': 0.16; 'set,': 0.16; 'subject:returning': 0.16; 'argument': 0.16; 'class,': 0.16; 'things.': 0.16; 'this?': 0.18; 'template': 0.20; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'cheers,': 0.20; 'subject:list': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr :python-list': 0.22; 'e.g.': 0.22; 'loop': 0.22; 'trying': 0.23; 'values': 0.23; 'item.': 0.23; 'keys': 0.23; 'modification': 0.23; 'version': 0.25; 'instead': 0.26; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.160': 0.28; 'class': 0.29; 'list': 0.30; 'cc:addr:python.org': 0.31; 'item,': 0.31; 'done': 0.32; 'received:209.85.160.46': 0.33; 'received:mail- pw0-f46.google.com': 0.33; 'using': 0.34; 'but,': 0.35; 'returned': 0.35; 'items.': 0.35; 'stuck': 0.35; 'typical': 0.35; 'doing': 0.36; 'appreciated.': 0.36; 'enough': 0.37; 'some': 0.37; 'background': 0.37; 'should': 0.37; 'received:209.85': 0.37; 'either': 0.37; 'apr': 0.38; 'received:google.com': 0.38; 'user': 0.38; 'but': 0.38; 'so,': 0.38; 'returning': 0.39; 'set': 0.39; 'where': 0.39; 'received:209': 0.39; 'how': 0.39; 'takes': 0.40; 'would': 0.40; 'header:Received:5': 0.40; 'might': 0.40; 'specialized': 0.60; '2011': 0.62; 'engine': 0.67; 'dict,': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=O68ApmMGsm+jGb1kdrSpklRnYScqDzQ0PfVc0UNroKY=; b=f/gxnpArnvLkNagayjgu6dRvH3oHC2cUx27jT6BtorKgToriZSlmGj7DgXMXICYoHo BDj/Yn1OYqurAKXmSVfqRwtfHYqYNRsjhiF6LhKFLinxHH5y3C7js9PHDuBSI0Vhid/a KSWWIOmYjdyAi3asUwU4GD9LWVu8NUkXCDpe8=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; b=ITWsWtWPfy+NCa44IQI83iKlfLtdQaas7cd+WfJAlqcyOKMOe+rh1l3yeB9wDTstgD /bZGHylt1k2IWK9ElVQ2SOqAp+wiV1slMh/yTSy9DwQqZVd6mrJNi7PsUJ/ripE7FWXS +aaow/aiU3Tno84Njb/gK1AN84nTMzeol2RYQ=
MIME-Version 1.0
In-Reply-To <89e48525-0bcc-4cc3-9f44-c3d86be3313c@34g2000pru.googlegroups.com>
References <89e48525-0bcc-4cc3-9f44-c3d86be3313c@34g2000pru.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Sun, 3 Apr 2011 02:02:28 -0600
Subject Re: Problem regarding returning list
To sl33k <ahsanbagwan@gmail.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.12
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>
Newsgroups comp.lang.python
Message-ID <mailman.159.1301817782.2990.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 82.94.164.166
X-Trace 1301817782 news.xs4all.nl 65870 [::ffff:82.94.164.166]:53717
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:2513

Show key headers only | View raw


On Sun, Apr 3, 2011 at 1:12 AM, sl33k <ahsanbagwan@gmail.com> wrote:
> I am trying to return a list of items modified with each item also
> showing like the number of modifications.
>
> Returning a list of user modified items was done easily but I would
> also like to display the item modified by the user and the
> modifications of that particular item.
> Typical way it coould be displayed like is,
> Modified item: No of modifications to it
>
> E.g. sl33k: 3
>
> Some background of the base class methods used:
>
> list_revisions() - gets the list of ints of the all modification of a
> particular item
> get_revision() - given the modification int, it gets the specific
> modified item.
> item.name gives the name of the item
> The method takes for argument the list of items.
>
> I start by declaring a set() of the total modified items. Using for
> loop in the items and in the for loop for particular `int`
> modification of it, I collect the modified item.
> But, I get stuck around when I have to collect the no of modifications
> for one. The set is returned as a list to a template engine for the
> display.
>
> So, I would like to collect for each item, its no of modifications.
> How would I go about doing this? How would i return it with list of
> modified items tp display the above shown example?
>
> Any pointers will be much appreciated.

Instead of a set, you should use a dict, where the keys are the items
and the values are the numbers of modifications.  Your return value
would either be the dict itself or the result of dict.items().

If you're using a recent enough version of Python, you might also have
a look at the collections.Counter class, which is a dict subclass that
is specialized for counting things.

Cheers,
Ian

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


Thread

Problem regarding returning list sl33k <ahsanbagwan@gmail.com> - 2011-04-03 00:12 -0700
  Re: Problem regarding returning list sl33k <ahsanbagwan@gmail.com> - 2011-04-03 00:17 -0700
  Re: Problem regarding returning list Ian Kelly <ian.g.kelly@gmail.com> - 2011-04-03 02:02 -0600

csiph-web