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


Groups > comp.lang.python > #2507 > unrolled thread

Problem regarding returning list

Started bysl33k <ahsanbagwan@gmail.com>
First post2011-04-03 00:12 -0700
Last post2011-04-03 02:02 -0600
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#2507 — Problem regarding returning list

Fromsl33k <ahsanbagwan@gmail.com>
Date2011-04-03 00:12 -0700
SubjectProblem regarding returning list
Message-ID<89e48525-0bcc-4cc3-9f44-c3d86be3313c@34g2000pru.googlegroups.com>
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.

Code:

def foo(items):

modified_items = set()
    rev_count = []
    for item in items:
        item_name = item.name
        revnos = item.list_revisions()
        for revno in revnos:
            revision = item.get_revision(revno)
            if modications userid == loggedin users userid:
                contribution_items.add(item_name)

          # How do i collect revisions here

return list(contribution_items)

[toc] | [next] | [standalone]


#2510

Fromsl33k <ahsanbagwan@gmail.com>
Date2011-04-03 00:17 -0700
Message-ID<ed6915b6-921c-46e9-bb14-a889ee0bf626@i35g2000prd.googlegroups.com>
In reply to#2507
On Apr 3, 3:12 am, sl33k <ahsanbag...@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.
>
> Code:
>
> def foo(items):
>
> modified_items = set()
>     rev_count = []
>     for item in items:
>         item_name = item.name
>         revnos = item.list_revisions()
>         for revno in revnos:
>             revision = item.get_revision(revno)
>             if modications userid == loggedin users userid:
>                 contribution_items.add(item_name)
>
>           # How do i collect revisions here
>
> return list(contribution_items)

I messed up with naming.
It should be
contribution_items = set()

[toc] | [prev] | [next] | [standalone]


#2513

FromIan Kelly <ian.g.kelly@gmail.com>
Date2011-04-03 02:02 -0600
Message-ID<mailman.159.1301817782.2990.python-list@python.org>
In reply to#2507
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web