Re: Is there an easy to "humanize" a list?

2006-12-20 Thread Waylan Limberg
On 12/20/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote: Waylan Limberg wrote: > Not that we need another way but this would work as well, and it > doesn't need special cases for one and two item lists but does insert > the "and" (unlike most of the solutions offered): > > def

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread James Bennett
On 12/20/06, Austin Govella <[EMAIL PROTECTED]> wrote: Is there an easy way to output that as: "foo, bar, and twinky" (There are handy functions for this in PHP, ColdFusion, and Rails, but my Google-fu fails for Python or Django.) As far as template logic is concerned, I do something similar

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread Fredrik Lundh
Brian Beck wrote: from django.utils.text import get_text_list doesn't match the OP's specification for all lists, though: >>> get_text_list(["one", "two", "three"], 'and') 'one, two and three' but I guess you could always do if len(seq) >= 2: text = get_text_list(seq, ", and")

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread Brian Beck
from django.utils.text import get_text_list --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group,

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread Fredrik Lundh
Waylan Limberg wrote: Not that we need another way but this would work as well, and it doesn't need special cases for one and two item lists but does insert the "and" (unlike most of the solutions offered): def humanize_list(list): return ", and".join(map(str, ", ".join(map(str,

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread Waylan Limberg
On 12/20/06, Austin Govella <[EMAIL PROTECTED]> wrote: Is there an easy way to output that as: "foo, bar, and twinky" Not that we need another way but this would work as well, and it doesn't need special cases for one and two item lists but does insert the "and" (unlike most of the

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread Jonathan Buchanan
On 12/20/06, Austin Govella <[EMAIL PROTECTED]> wrote: I have a list from a queryset: * foo * bar * twinky Is there an easy way to output that as: "foo, bar, and twinky" (There are handy functions for this in PHP, ColdFusion, and Rails, but my Google-fu fails for Python or Django.)

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread Fredrik Lundh
James Aylett wrote: Is there an easy way to output that as: "foo, bar, and twinky" If you want to do it in python, use reduce: -- # l is the list, r is the humanised result r = reduce(lambda x, y: str(x) + "," + str(y), l)

Re: Is there an easy to "humanize" a list?

2006-12-20 Thread James Aylett
On Wed, Dec 20, 2006 at 08:27:11AM -0500, Austin Govella wrote: I have a list from a queryset: * foo * bar * twinky Is there an easy way to output that as: "foo, bar, and twinky" If you want to do it in python, use reduce:

Is there an easy to "humanize" a list?

2006-12-20 Thread Austin Govella
I have a list from a queryset: * foo * bar * twinky Is there an easy way to output that as: "foo, bar, and twinky" (There are handy functions for this in PHP, ColdFusion, and Rails, but my Google-fu fails for Python or Django.) Thanks, -- Austin Govella Thinking & Making: IA, UX, and IxD