Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Dictionary pagination
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
David  
View profile  
 More options Nov 4, 1:32 pm
From: David <ww...@yahoo.com>
Date: Wed, 4 Nov 2009 10:32:49 -0800 (PST)
Local: Wed, Nov 4 2009 1:32 pm
Subject: Dictionary pagination
Hello,

I just wonder if anybody has handled this before. Here is a 2-D
dictionary.

dict[key_1] = {'a':'aa', 'b':'bb', 'c':'cc'}
dict[key_2] = {'a':'dd', 'b':'ee', 'c':'ff'}
dict[key_3] = {'a':'eef', 'b': 'ff', 'c':'ghh'}
............

Assume that this dict is so long that I need to paginate. Do I need to
convert it to a list in order to use Paginator
?

Is there a good way to paginate this dictionary?

Thanks for your ideas.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bill Freeman  
View profile  
 More options Nov 4, 2:01 pm
From: Bill Freeman <ke1g...@gmail.com>
Date: Wed, 4 Nov 2009 14:01:37 -0500
Local: Wed, Nov 4 2009 2:01 pm
Subject: Re: Dictionary pagination

You at least need to list the keys, say by using the keys() method.
The trouble with
thinking of paginating a dictionary is that it has no inherent order.
When you go back
for items n through 2n-1, for example, there is no guarantee that what
you get won't
share items with the first 0-n.  That the order may seem stable in
casual testing is an
implementation detail that you shouldn't depend on.

Probably you want to sort this somehow too, so that the presentation
order makes sense.
So something like:

    ks = d.keys()
    ks.sort()

Then for page p of n items:

    for k in ks[n*(p-1):n*p]:
        v = d[k]

Note that if pages are displayed across multiple requests, you need to
put ks somewhere that its value will be preserved until the next
request.  Or if you're sure that d won't change between requests, just
do the call to the keys method and the sort each time.

[Note, too, re your sample, that "dict" is a bad name for a dictionary
variable, because it is also the name of the type.  It will work, but
it will get confusing.]

Bill


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David  
View profile  
 More options Nov 4, 2:28 pm
From: David <ww...@yahoo.com>
Date: Wed, 4 Nov 2009 11:28:27 -0800 (PST)
Local: Wed, Nov 4 2009 2:28 pm
Subject: Re: Dictionary pagination
Thanks Bill. Your reply is quite helpful.

On Nov 4, 12:01 pm, Bill Freeman <ke1g...@gmail.com> wrote:


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google