Problem regarding returning list

S

sl33k

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)
 
S

sl33k

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()
 
I

Ian Kelly

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top